Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So I want to make an SQL query that returns a set of rows and also sets a certain column in those rows to null. So if I had a table like

column1 column2 column3
a       b       c
a       b       d
e       f       g

I would want to do the pseudo-SQL SELECT * FROM table WHERE column1 = a AND ALSO SET column2 = null and have that return my first two rows as they are above, while leaving the table looking like

column1 column2 column3
a       null    c
a       null    d
e       f       g

Can I do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
183 views
Welcome To Ask or Share your Answers For Others

1 Answer

DECLARE @column1 varchar(2);
SET @column1 = (SELECT distinct column1 FROM table WHERE column1 = 'a' );

select * from table where column1 = @column1;
update table set column2 = null where column1 = @column1;

this work for me in sql server..which will return the row as it is earlier and will update the column with new values in background


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...