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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Pivoting

Author  Topic 

OBINNA_EKE
Posting Yak Master

234 Posts

Posted - 2009-05-18 : 10:57:50
I have this table structure below
INSERT INTO [Setting]
(
SettingID,
MoceanUsername,
Test
)
VALUES
(
@SettingID,
@MoceanUsername,
@Test
)
when I am displaying it on SQL or C# Is it posible to have this kind of structure?

Columns Value
SettingID 1000
MoceanUsername SuperUser
Test Yes

Therefore switching the rows to two colums only?
If it it possible, any help will be appreciated

(My data will only have one row only)



If it is that easy, everybody will be doing it

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-19 : 02:33:52
select 'Settingid' as columns, cast(Settingid as varchar(100)) as value from [Setting]
union all
select 'MoceanUsername' as MoceanUsername, MoceanUsername from [Setting]
union all
select 'Test' as Test, Test from [Setting]


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-19 : 10:10:45
if you're using sql 2005, you can UNPIVOT also for this.
Go to Top of Page
   

- Advertisement -