Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi,Is it possible to store result of a select of the same column in more than one variable:This is what result is:AAAABBBBCCCCI would like to store the 3 different values into different variables.Is it possible without using cursor?Thanks,--------------------------Get rich or die trying--------------------------
first explain us whats the need for this requirement------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Lamprey
Master Smack Fu Yak Hacker
4614 Posts
Posted - 2012-07-19 : 11:36:48
Here is one way:
DECLARE @A VARCHAR(50), @B VARCHAR(50), @C VARCHAR(50)DECLARE @Foo TABLE (Val VARCHAR(50))INSERT @FooVALUES ('AAAA'),('BBBB'),('CCCC')SELECT @A = [AAAA], @B = [BBBB], @C = [CCCC]FROM(SELECT Val FROM @Foo) AS SourcePIVOT( MAX(Val) FOR Val IN ([AAAA], [BBBB], [CCCC])) AS PivSELECT @A, @B, @C