October 17, 2012 at 12:17 pm
DECLARE @lClub_group_joined_test varchar(20)
SELECT @lClub_group_joined_test = club_group_id
FROM dba.t_club_group
WHERE acct_id = @iAcctid
UPDATE #temp_ticket t
SET t.club_group_joined = STRING(t.club_group_id_col, ',', CONVERT(date, t.club_group_joined_datetime))
WHERE t.club_group_id_col = CASE WHEN t.club_group_id_col = @lClub_group_joined_test THEN t.club_group_id_col
WHEN t.club_group_id_col <> @lClub_group_joined_test THEN NULL
END
AND t.club_group_joined_datetime IS NOT NULL
Here is my update statement. What I am trying to do is,
in the set statement, when t.club_group_id_col = @lClub_group_joined_test then only update
Else I need to set Whole COLUMN called t.club_group_joined = NULL.
But i m having hard time, can u write me that code part only?
October 17, 2012 at 12:32 pm
dallas13 (10/17/2012)
DECLARE @lClub_group_joined_test varchar(20)SELECT @lClub_group_joined_test = club_group_id
FROM dba.t_club_group
WHERE acct_id = @iAcctid
UPDATE #temp_ticket t
SET t.club_group_joined = STRING(t.club_group_id_col, ',', CONVERT(date, t.club_group_joined_datetime))
WHERE t.club_group_id_col = CASE WHEN t.club_group_id_col = @lClub_group_joined_test THEN t.club_group_id_col
WHEN t.club_group_id_col <> @lClub_group_joined_test THEN NULL
END
AND t.club_group_joined_datetime IS NOT NULL
Here is my update statement. What I am trying to do is,
in the set statement, when t.club_group_id_col = @lClub_group_joined_test then only update
Else I need to set Whole COLUMN called t.club_group_joined = NULL.
But i m having hard time, can u write me that code part only?
You have over 1,000 points on here so the concept of posting some ddl and sample in addition to desired output is not new to you. Take a look at the first link in my signature about best practices.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
November 1, 2012 at 4:50 am
pls provide ddl data based on that data i will provide query...
November 2, 2012 at 5:44 am
Probably something like this..
UPDATE#temp_ticket
SETclub_group_joined = CASE
WHEN club_group_id_col = @lClub_group_joined_test
THEN STRING(club_group_id_col, ',', CONVERT(date, club_group_joined_datetime))
ELSE NULL
END
WHEREclub_group_joined_datetime IS NOT NULL
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply