Popkatapetapotapulti Posted February 13, 2017 Report Posted February 13, 2017 I have a query like this DECLARE @display nvarchar(4000) set @display = '' SELECT @display = @display_value + t1.title ', ' FROM table_name t1 JOIN dbo.fn_array_to_int(@value) f on t1.id = f.value fn_array_to_int - obvious from name it converts '1,2,3' to int for each row... sample data for table_name id title 1 No 2 Yes 3 Alright if you run above query with @value as '1,2,3'....it will return @display as 'No, Yes, Alright' . Now my question is how do you put this in case statement SELECT CASE WHEN type IN (4,5,6) THEN @display = @display_value + t1.title ', ' ELSE '' END from table t1 --some other table joins Quote
papacha Posted February 13, 2017 Report Posted February 13, 2017 inkonchem elaborate cheyagalara? or naaku ardham aina varaku try this SELECT CASE WHEN type IN (4,5,6) THEN @display_value + t1.title ', ' ELSE '' END as xyz = @display from table t1 Quote
samaja_varagamana Posted February 13, 2017 Report Posted February 13, 2017 I will look into it and let u know Quote
Popkatapetapotapulti Posted February 13, 2017 Author Report Posted February 13, 2017 26 minutes ago, papacha said: inkonchem elaborate cheyagalara? or naaku ardham aina varaku try this SELECT CASE WHEN type IN (4,5,6) THEN @display_value + t1.title ', ' ELSE '' END as xyz = @display from table t1 if you do this what happens is you will get as below..it wont concatenate 1 No 2 Yes 3 Alright 1 Quote
papacha Posted February 13, 2017 Report Posted February 13, 2017 what is the result you are looking for? Quote
Popkatapetapotapulti Posted February 13, 2017 Author Report Posted February 13, 2017 Just now, papacha said: what is the result you are looking for? 1,2,3 | No,Yes, Alright Quote
Popkatapetapotapulti Posted February 14, 2017 Author Report Posted February 14, 2017 6 minutes ago, papacha said: what is the result you are looking for? SELECT col1, @display_value=(CASE WHEN type IN (4,5,6) THEN @display_value + t1.title ', ' ELSE '' END) ela pedithey "A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations." Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.