‘壹’ 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赋值语句
declare @newtitle varchar(50)
select @newtitle=title from table
print @newtitle
表里即使有多条数据 @newtitle 也只有一个值 (最后那条记录的title,SQL 没有数组)
select @newtitle=title from table where......
print @newtitle
特定记录的 title
‘叁’ sql语句中如何对某个为空的字段赋值
你是在查询的时候操作还是要做更新操作
是空还是null
查询时操作
NULL
select isnull(字段名, '复制)
select replace(字段名, ' ', '赋值')
更新操作
空
update 表名
set 字段名=内容
where 字段名 =''
NULL
update 表名
set 字段名=内容
where 字段名 is null
‘肆’ sql怎么赋值
唉。。。
@t='a' --是把'a'赋值给@t
如果 @t的值已经是'a'了 那么
@b=@t 就是把@t的值又赋值给@b
你这个@table_name 从头到尾都没赋过值 拿什么给@TableName赋值啊
(注:sql 不区分大小写 如果你是程序代码习惯可以有,用不同大小写来区分不同变量就不行了)
‘伍’ 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 就知道变量的值了
‘陆’ 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后,将时间段from_datetime至to_datetime内,将"col1"的最大值赋给y_report.ANGX_max。
‘捌’ SQL赋值语句
declare
@newtitle
varchar(50)
select
@newtitle=title
from
table
print
@newtitle
表里即使有多条数据
@newtitle
也只有一个值
(最后那条记录的title,sql
没有数组)
select
@newtitle=title
from
table
where......
print
@newtitle
特定记录的
title
‘玖’ SQL赋值是什么
declare @i int
set @i = 1
select @i = 2