city(id,c_name,c_fatherID)是一般的城市列表,现在想通过表量@name得到表中某父子相加的值,如广东广州,语句如下:declare @fatherID int
declare @name varchar(100)
set @fatherID=2
while @fatherID>0
begin
select @fatherID=c_fatherID,@name=@name+c_name from City where id=@fatherID
print 1 ---这里显示循环了两次
end
print @name --------print出来的是空请各位看看是怎么回事?
declare @name varchar(100)
set @fatherID=2
while @fatherID>0
begin
select @fatherID=c_fatherID,@name=@name+c_name from City where id=@fatherID
print 1 ---这里显示循环了两次
end
print @name --------print出来的是空请各位看看是怎么回事?
declare @name varchar(100)
set @name='' --赋初值,不然就是NULL
set @fatherID=2
while @fatherID>0
begin
select @fatherID=c_fatherID,@name=@name+c_name from City where id=@fatherID
print 1 ---这里显示循环了两次
end
print @name --------print出来的是空
update table set col=col+'测试字符串'这种情况下即使列col是null也可以加入呢?
set @i=1
--set @j=2 --这句去了你试试
print @i+@j
set @name=''
避免null出现
select @fatherID=c_fatherID,@name=@name+isnull(c_name,'') from City where id=@fatherID
而且为什么如:
update table set col=col+'测试字符串'这种情况下即使列col是null也可以加入呢?
---------------------------------------------
楼主是怎么测试的啊???不可能吧!drop table [table]
go
create table [table](col varchar(100))
insert into [table]
select '111'
union select NULL
union select '222'update [table] set col=col+'测试字符串'select * from [table]
/*
col
-----------------------
NULL
111测试字符串
222测试字符串(所影响的行数为 3 行)
*/
谢谢,是我测试错了,我想问你,null与任何数据进行逻辑运算结果都是null?