我有选择数据的程序。
SELECT my_id FROM myDB WHERE @u_id = [u_id]
现在我需要类似的东西:
if my_id = 1
set @anotherID = '10'
我有选择数据的程序。
SELECT my_id FROM myDB WHERE @u_id = [u_id]
现在我需要类似的东西:
if my_id = 1
set @anotherID = '10'
你的问题很模糊,我不确定你真正追求的是什么,但试试这样的事情:
--your existing code
SELECT my_id FROM myDB WHERE @u_id = [u_id] --returns a result set,
-- of possibly many rows
--add this
if exists (select 1 from myDB WHERE @u_id = [u_id] AND my_id=1)
BEGIN
SET @anotherID = '10' --hopefully you have declared this variable
--if @anotherID is a int/numeric data type
-- you should just use: SET @anotherID = 10
-- notice the removed quotes
END
declare @my_Id int
SELECT @my_Id = my_id FROM myDB WHERE @u_id = [u_id]
if(@my_ID = 1)
BEGIN
set @anotherID = '10'
END
声明@anotherId int
选择@anotherId =(当 my_id = 1 然后 10 时的情况,否则 @anotherId End )
来自@u_id = [u_id]