有一个表是只有的:sn ts1 ts2 ts3 ts41 你好 很好 不错 不错啊2 他们 他们啊 他们是不 他们是不啊3 看到 什么 不可以 不可以45现在的问题是在第4行,也就是sn为4的那行,当我输入‘ts1’ 为 '你好' 的时候 第4行的记录 会自动复制于 ts2 ts3 ts4 于第4行的字段结果如下:sn ts1 ts2 ts3 ts41 你好 很好 不错 不错啊2 他们 他们啊 他们是不 他们是不啊3 看到 什么 不可以 不可以4 你好 很好 不错 不错啊5
有一个表是只有的:sn ts1 ts2 ts3 ts41 你好 很好 不错 不错啊2 他们 他们啊 他们是不 他们是不啊3 看到 什么 不可以 不可以45现在的问题是在第4行,也就是sn为4的那行,当我输入‘ts1’ 为 '你好' 的时候 第4行的记录 会自动复制于 ts2 ts3 ts4 于第4行的字段结果如下:sn ts1 ts2 ts3 ts41 你好 很好 不错 不错啊2 他们 他们啊 他们是不 他们是不啊3 看到 什么 不可以 不可以4 你好 很好 不错 不错啊5
ts2=B.ts2,
ts3=B.ts3,
ts4=B.ts4
FROM tb AS A
CROSS JOIN tb AS B
WHERE A.sn=4
AND B.ts1='你好'
-- Author: liangCK 小梁
---------------------------------
--> 生成测试数据: @T
DECLARE @T TABLE (sn INT,ts1 VARCHAR(4),ts2 VARCHAR(6),ts3 VARCHAR(8),ts4 VARCHAR(10))
INSERT INTO @T
SELECT 1,'你好','很好','不错','不错啊' UNION ALL
SELECT 2,'他们','他们啊','他们是不','他们是不啊' UNION ALL
SELECT 3,'看到','什么','不可以','不可以' UNION ALL
SELECT 4,null,null,null,null UNION ALL
SELECT 5,null,null,null,null--SQL查询如下:UPDATE A SET
ts1=B.ts1,
ts2=B.ts2,
ts3=B.ts3,
ts4=B.ts4
FROM @T AS A
CROSS JOIN @T AS B
WHERE A.sn=4
AND B.ts1='你好'
SELECT * FROM @T;/*
sn ts1 ts2 ts3 ts4
----------- ---- ------ -------- ----------
1 你好 很好 不错 不错啊
2 他们 他们啊 他们是不 他们是不啊
3 看到 什么 不可以 不可以
4 你好 很好 不错 不错啊
5 NULL NULL NULL NULL(5 行受影响)*/
declare @output22 varchar(8000)
select @output2 = coalesce(@output2 + '/' , '') + b.bprocessid_name+'1' from Pro_WorkProject_Detail3_vi a inner join Pro_WorkProject_Detail7_vi b on a.sbillno=b.sbillno and a.wpartname=b.bpartid and a.irecno=b.iprecno where a.irecno=2 and a.sbillno='09040211'
select @output22 = coalesce(@output22 + '/' , '') + b.wtech_name from Pro_WorkProject_Detail3_vi a inner join Pro_WorkProject_Detail2_vi b on a.sbillno=b.sbillno and a.wpartname=b.wpartid and a.irecno=b.iprecno where a.irecno=2 and a.sbillno='09040211'
create table c(help varchar(100))
insert into c values( @output2 + '/' + @output22)
select * from c
drop table c上面你看到 如果@output2为空的时候,整个记录就都为空了 但是我@output22是选择出来有值的 那就想体现出@output2的值啊 也就是说不管@output2是不是空的 都可选正常得出到两个加起来的值
ts1=B.ts1,
ts2=B.ts2,
ts3=B.ts3,
ts4=B.ts4
FROM @T AS A
CROSS JOIN @T AS B
WHERE A.sn=4
AND B.ts1='你好'
AND B.ts1='你好' 这个条件不是固定的啊
有的时候ts1会等于其他的呀 不知道你们有没有看懂我说的意思