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 2000 Forums
 Transact-SQL (2000)
 Select query statement

Author  Topic 

seyha_moth
Yak Posting Veteran

74 Posts

Posted - 2006-12-06 : 02:19:47
Dear Sir or Madam

I'm glad to join this forum related to sql language and I hope that I'll get the good knowledge from here.

I have the problem related to select statement is that

Declare @Str nvarchar(4000)
set @Str=''

Set @St=@Str+'Address,DateofBirth,'

Select FullName,StudentID,Sex,@Str from tblStudent

When I execute the above sql query,it show

FullName StudentID Sex (No Column Name)
seyha 7845 M Address,DateOfBirth
chanta 7444 F Address,DateOfBirth

But I want to get the result

FullName StudentID Sex Address DateOfBirth
seyha 7845 M PP 17-04-1975
chanta 7444 F KG 25-04-1985

I hope that all of u can help me,Thank u in advance

I look forward to hearing from u
Good Luck and Suceed your study and work






seyha moth

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-12-06 : 02:22:13
[code]Select FullName,StudentID,Sex,Address,DateofBirth from tblStudent[/code]

or if you insist to use variable, use dynamic sql:

[code]Set @St=@Str+'Address,DateofBirth'

EXEC('Select FullName,StudentID,' + @str + ' from tblStudent')
[/code]

But I don't see a reason to use D-SQL.

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

seyha_moth
Yak Posting Veteran

74 Posts

Posted - 2006-12-06 : 02:36:54
Thank you for your reply and I solve successfully my problem with your solution

Thank you very much
I hope that I can help if you have the problem

I look forward to hearing from you
Good Luck and Succed your work and study.
Good bye!!

seyha moth
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-06 : 10:57:41
<<
I'm glad to join this forum related to sql language and I hope that I'll get the good knowledge from here.
>>

Sure. Make sure you read this fully
www.Sommarskog.se/Dynamic_sql.html

Madhivanan

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

- Advertisement -