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)
 Merge Resault of storedprocedure

Author  Topic 

Dajer
Starting Member

22 Posts

Posted - 2009-08-22 : 06:59:06
hi friends
suppose that I have a table with 2 columns:ID , Name
I 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 attention

Sara 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?
Go to Top of Page

Dajer
Starting Member

22 Posts

Posted - 2009-08-22 : 07:12:20
select ID,Name from table1

ID Name
--- -----
1 s
2 d

But I want this:

ID/Name
-------
1/s
2/d

Sara Dajer
Go to Top of Page

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
Go to Top of Page

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
Go to Top of Page

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 this
select cast(id as varchar(32))+'/'+Name AS [ID/Name] from table1
Go to Top of Page

Dajer
Starting Member

22 Posts

Posted - 2009-08-23 : 03:00:09
thx.it works.
But a question:why we use 'cast'?

Sara Dajer
Go to Top of Page

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]

Go to Top of Page

Dajer
Starting Member

22 Posts

Posted - 2009-08-23 : 03:17:47
thx alot.

Sara Dajer
Go to Top of Page
   

- Advertisement -