Just check this sample , you have to use charindex(to find the index of comma) and substring function to get substring value Declare @var varchar(50) = ‘21699,21712’ select charindex( ‘,’, @var), substring ( @var, charindex(‘,’, @var)+1, len(@var)) you can also use this too: declare @var varchar(50) = ‘21699,21712’ select charindex( ‘,’, @var), substring ( @var, … Read more

[Solved] Getting Data separated by comma, [duplicate]

Like here, here or here. SELECT [TicketId], STUFF(( SELECT ‘, ‘ + [Name]) FROM [OneTable] WHERE ([TicketId] = OT.[TicketId]) FOR XML PATH(”),TYPE).value(‘(./text())[1]’,’VARCHAR(MAX)’) ,1,2,”) AS Name FROM [OneTable] OT GROUP BY [TicketId] Go and vote it up, then close this question. 1 solved Getting Data separated by comma, [duplicate]

[Solved] T-SQL (Un)Pivot Table

I usually use dynamic sql. Something like this create table #T ( ID int, aText1 varchar(4), aText2 varchar(4), aInt1 int, aInt2 int ) insert into #T select 1, ‘ABC1’, ‘XYZ1’, 2, 20 union select 2, ‘ABC1’, ‘XYZ2’, 3, 25 union select 3, ‘ABC2’, ‘XYZ2’, 1, 30 union select 4, ‘ABC2’, ‘XYZ1’, 4, 35 declare @sql … Read more

[Solved] How to convert varchar time to 24hours Time in SQL Server [closed]

Not clear whether you want your result as a VARCHAR or an actual TIME type, so here’s both: DECLARE @Table TABLE ( TXN_TIME VARCHAR(6) ) INSERT INTO @Table SELECT ‘053124’ UNION SELECT ‘173932’ UNION SELECT ‘011815’ UNION SELECT ‘120349’ UNION SELECT ‘134207’ SELECT TXN_TIME, LEFT(TXN_TIME,2) + ‘:’ + SUBSTRING(TXN_TIME,3,2) + ‘:’ + SUBSTRING(TXN_TIME,5,2) + ‘:000000’ … Read more

[Solved] Can I use an Expression to set a variable in a “SQL Statement Task”?

If you are talking about the “Execute SQL Task”, expressions are possible. Here what I usually do is to configure the type as “direct input” and then define the whole statement – including my parametrized values – as expression. If you rightclick the task, you can select properties and in the properties you open the … Read more