Monday, March 11, 2013

[T-SQL] Group a set of chain values

[T-SQL] Group a set of chain values


Group a set of chain values

Posted: 10 Mar 2013 07:28 PM PDT

I have the following table in SQL Server 2008[code="sql"]DECLARE @UnitConvert table ( ID int identity(1,1), ConvertUnitOne nvarchar(50), ConvertUnitTwo nvarchar(50)) INSERT INTO @UnitConvertSELECT 100,500UNION ALL SELECT 200,100UNION ALL SELECT 500,300UNION ALL SELECT 2000,1000UNION ALL SELECT 3000,9000UNION ALL SELECT 2000,700UNION ALL SELECT 820,3000SELECT * FROM @UnitConvert[/code]Here value in UnitConvertOne is equivalent to UnitConvertTwo So it has a chain of value linking100 = 500,200=100,500=300..so 100,200,300,500 make a groupSo i want to display the result like[code="plain"] Group unit1 100 200 300 5002 700 1000 20003 820 3000 9000[/code]Group value will be autoincrement based on the number of groups can be created, Unit value can be sorted from small to large value

Combine variable and select statement

Posted: 10 Mar 2013 08:49 PM PDT

I want to combine this select statement and a variable(@EndUserDel) to get result.how can i do that?[code="sql"] declare @EndUserDel nvarchar(20)select * FROM [dbo].[Service][/code]i want this way select *,@EndUserDel FROM [dbo].[Service]how can i do that

No comments:

Post a Comment

Search This Blog