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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to bring this result

Author  Topic 

urzsuresh
Starting Member

30 Posts

Posted - 2011-07-05 : 00:56:02
Hi,
Below one is my sample Table Structure

Declare @t table
(
Series varchar(50),
S1 varchar(50),
S2 varchar(50),
S3 varchar(50)
)

Insert into @t
Select 'Label1','','','' union
Select 'Label2','','','' union
Select 'Label3','','','' union
Select 'Label4','','',''

Select * from @t

Above OutPut

Series S1 S2 S3
Label1
Label2
Label3
Label4

Actually Label1,2,3 were fetch from table, the value may change. So My required output
is like below

Series S1 S2 S3
Label1
Open
Close
Label2
Open
Close
Label3
Open
Close
Label4
Open
Close

Need to bring Open and close between of the Every labels. How to bring achieve the above result.Kindly guide me,through sample codes
.


Suri

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-05 : 03:26:59
Sorry but that looks senseless.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-07-05 : 04:19:57
What defines "open" and "close"?



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-07-05 : 14:05:25
you mean get open and close as values within series fieldS?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2011-07-05 : 14:19:28
I think he just wants to get the open & close records inbetween the records from the table:


Select
r = A.r + B.n,
Series = case B.n when 0 then A.Series when 1 then 'Open' when 2 then 'Close' else null end,
S1 = case B.n when 0 then A.S1 else '' end,
S2 = case B.n when 0 then A.S2 else '' end,
S3 = case B.n when 0 then A.S3 else '' end
From
(
Select
r = ROW_NUMBER() Over(Order By Series) * 3-2,
*
From @t
) A
Cross Join (Select n=0 Union All Select 1 Union All Select 2) B


EDIT: Not sure why this is desired though...

Corey

I Has Returned!!
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-05 : 14:27:59
[code]select '
Series S1 S2 S3
Label1
Open
Close
Label2
Open
Close
Label3
Open
Close
Label4
Open
Close'
[/code]



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -