当前位置:首页 » 编程语言 » sql语句赋值

sql语句赋值

发布时间: 2023-03-30 07:46:10

sql语句中如何对某个为空的字段赋值

你是在查询的时候操作还是要做更新操作
是空还是null
查询时操作
NULL
select isnull(字段名, '复制)
select replace(字段名, ' ', '赋值')

更新操作

update 表名
set 字段名=内容
where 字段名 =''
NULL
update 表名
set 字段名=内容
where 字段名 is null

Ⅱ mysql环境中,如何用sql语句给字符串变量赋值

mysql给字符串变量赋值的方法是用select into 变量结构完成赋值。
使用sql的结构语法:
SELECT ... INTO var_list selects column values and stores them into variables.
比如定义一个sql变量:
@x varchar(10);
@y varchar(20);
select id,name INTO @x,@y from dx_tt
这样就完成了赋值。

Ⅲ Sql中如何给变量赋值

/*

Sql server 存储过程中怎么将变量赋值

*/

--SQL赋值语句

DECLARE @test1 INT

SELECT @test1 = 111

SET @test1 = 222

--SQL函数赋值,假定count()是自定义函数

DECLARE @test2 INT

SELECT @test2 = COUNT(*) FROM sys.sysobjects

--SQL存储过程赋值,直接传参处理(类似C语言中的指针吗)

IF OBJECT_ID('sp_test') IS NOT NULL DROP PROCEDURE sp_test

GO

CREATE PROCEDURE sp_test(@test INT OUTPUT)

AS

BEGIN

SELECT @test = 999

GO

DECLARE @test3 INT

EXEC sp_test @test3 OUTPUT

SELECT @test3

DROP PROCEDURE sp_test

GO

Ⅳ 关于SQL中的赋值

就是动态拼凑出一个sql语句啊,然后执行这个sql语句
例:declare @sql nvarchar(1000)
set @sql='select * from table_name where '
set @sql=@sql+'id=2'
exec (@sql)

这样这个sql语句就相当于是:
select * from table_name where id=2

Ⅳ 如何把sql语句查询到的值赋值给变量

//多行
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("server=.;database=你的数据库的名字;uid=sa;pwd=sa的密码;");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.Connection = conn;
cmd.CommandText="select 字段A from 表B where years=2000 and months=2";
conn.Open();
System.Data.SqlDataAdapter sda=new System.Data.SqlDataAdapter(cmd);
DataSet ds=new DataSet();
sda.Fill(ds,"dtResult");
conn.Close();
//结果在ds的dtResult中。
foreach(DataRow dr in ds.Tables["dtResult"])
{
Response.Write(dr["字段A"].ToString()+"<br>");
}
-------------------------------------------------------------
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("server=.;database=你的数据库的名字;uid=sa;pwd=sa的密码;");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.Connection = conn;
cmd.CommandText="select 字段A from 表B where years=2000 and months=2";
conn.Open();
int i=Convert.ToInt32(cmd.ExecuteScalar().ToString());
conn.Close();

Ⅵ sql语句,给字段赋值

字符串里的团脊颤单引号用''(即两个单引号)表示

updatehtgl_tx_logsetrolbk_sql='野伍updatehtgl_tx_logsettx_date=11111111wherehtgl_tx_no=''6''|updatehtgl_tx_logsettx_time=111111wherehtgl_tx_no=''6'''
WHERE塌败HTGL_TX_NO='6'

Ⅶ Sql中如何给变量赋值

DECLARE @n1 int,@n2 varchar(10)
set @n1 =(select age from table where column=xxx)
set @n2=(select gender from table where column = xxx )
------------------
或者一起赋值
就是楼上那个
DECLARE @n1 int,@n2 varchar(10)
select @n1 =age,@n2=gender
from table where column = xxx
------------------
select @n1,@n2 就知道变量的值了

热点内容
app什么情况下找不到服务器 发布:2025-05-12 15:46:25 浏览:714
php跳过if 发布:2025-05-12 15:34:29 浏览:467
不定时算法 发布:2025-05-12 15:30:16 浏览:131
c语言延时1ms程序 发布:2025-05-12 15:01:30 浏览:167
动物园灵长类动物配置什么植物 发布:2025-05-12 14:49:59 浏览:738
wifi密码设置什么好 发布:2025-05-12 14:49:17 浏览:150
三位数乘两位数速算法 发布:2025-05-12 13:05:48 浏览:399
暴风影音缓存在哪里 发布:2025-05-12 12:42:03 浏览:545
access数据库exe 发布:2025-05-12 12:39:04 浏览:632
五开的配置是什么 发布:2025-05-12 12:36:37 浏览:367