Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stored procedure - concatenate string and integer 2

Status
Not open for further replies.

ksbigfoot

Programmer
Joined
Apr 15, 2002
Messages
856
Location
CA
I am using SQL Server 8.0
I wrote a stored procedure that performs a distinct on one field.

Current Query:
Select Distinct FieldOne FROM Table1

Query I need to do something like this (not working):
Select 'P,' + Distinct FieldOne As NewResult FROM Table1

FieldOne is an Integer field

Current values Values I need returned
10 P,10
20 P,20
30 P,30
35 P,35

Do I have to do a TypeCast or something like that?
Thanks
 
what result do you want
[Code Sql]
Select Distinct 'p,' + convert(varchar(4), FieldOne ) as
NewResult FROM Table1

[/code]
 
Howdy pwise and nice95gle,

pwise, that is exactly what I was looking for. Star to you. Why varchar(4) instead of varchar(15) or NVARCHAR?

nice95gle, I did look at that post, but I didn't understand it with all the quotes they were using and they are using a NVARCHAR.

Thanks again and star to you both,
ksbigfoot

 
if you need more than varchar(4) use that this was just a quick post to show what to do
 
Howdy pwise,
Ok, I understand.
My numbers are a max of 7 in length, so I used varchar(7).
Thanks again,
ksbigfoot
 
I'm sorry, all you needed to do was.

select distinct 'P'+cast(FieldOne as varchar(7)) As NewResult from Table1

Well Done is better than well said
- Ben Franklin
 
Howdy nice95gle,
Thanks for the last post, I gave you a star before your last post.
You did answer my question by saying casting from int to varchar.
I really appreciate that you added another post with an example.

Thanks again,
ksbigfoot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top