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.
| Author |
Topic |
|
Dajer
Starting Member
22 Posts |
Posted - 2009-08-22 : 06:59:06
|
| hi friendssuppose that I have a table with 2 columns:ID , NameI can easily filter ID and Name from DB.but Imagine that I want to see these 2 fields beside eachother:ID/Name(exactly in this appearance)Is it possible to do this in my storedprocedure?If 'YES' HOW?thx for your attentionSara Dajer |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-08-22 : 07:06:44
|
| can u please post some sample data and required output? |
 |
|
|
Dajer
Starting Member
22 Posts |
Posted - 2009-08-22 : 07:12:20
|
| select ID,Name from table1ID Name--- -----1 s2 dBut I want this:ID/Name-------1/s2/dSara Dajer |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-08-22 : 08:01:10
|
| Hi Try this once,select cast(id as varchar(32))+'/'+Name AS 'ID/Name' from @temp |
 |
|
|
Dajer
Starting Member
22 Posts |
Posted - 2009-08-22 : 13:39:57
|
| sorry for my delay.I test it.It doesn't work.It has Error:"The Multi-part identifier "id" could not be bound.The Multi-part identifier "Name" could not be bound."Sara Dajer |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2009-08-22 : 15:40:54
|
works when i run it. maybe you have a typo?might try like thisselect cast(id as varchar(32))+'/'+Name AS [ID/Name] from table1 |
 |
|
|
Dajer
Starting Member
22 Posts |
Posted - 2009-08-23 : 03:00:09
|
| thx.it works. But a question:why we use 'cast'?Sara Dajer |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-08-23 : 03:07:43
|
it is assumed that your column id is an integer or numeric type. To perform string concatenation, you need to convert it to string first. CAST() is to convert that to string. You may also use CONVERT() to do that. KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Dajer
Starting Member
22 Posts |
Posted - 2009-08-23 : 03:17:47
|
| thx alot.Sara Dajer |
 |
|
|
|
|
|