PC Review


Reply
Thread Tools Rate Thread

how to concate two integers in select statement

 
 
haiwen
Guest
Posts: n/a
 
      18th Jul 2003
hello, everyone:

we can concate two strings when changing column name, such
as: select firstname +' ' + lastname as name from user;

but how can I concate two intergers(treat them as strings)?
when I use +, I alway get the result of addition.

Thanks

haiwen
 
Reply With Quote
 
 
 
 
suzy
Guest
Posts: n/a
 
      18th Jul 2003
try convert.ToString(number1) + convert.ToString(number2).

if you want to convert the result to a number then wrap the above command
around a

convert.ToInt64 command.

hope this helps, let me know!



"haiwen" <(E-Mail Removed)> wrote in message
news:022301c34d6d$df36a420$(E-Mail Removed)...
> hello, everyone:
>
> we can concate two strings when changing column name, such
> as: select firstname +' ' + lastname as name from user;
>
> but how can I concate two intergers(treat them as strings)?
> when I use +, I alway get the result of addition.
>
> Thanks
>
> haiwen



 
Reply With Quote
 
Tu-Thach
Guest
Posts: n/a
 
      18th Jul 2003
You need to CONVERT/CAST the columns into string (VARCHAR)
first then add them.

Tu-Thach

>-----Original Message-----
>hello, everyone:
>
>we can concate two strings when changing column name,

such
>as: select firstname +' ' + lastname as name from user;
>
>but how can I concate two intergers(treat them as

strings)?
>when I use +, I alway get the result of addition.
>
>Thanks
>
>haiwen
>.
>

 
Reply With Quote
 
haiwen
Guest
Posts: n/a
 
      18th Jul 2003
hi, thank you for your help.

I try it, but I get the exception:

Exception Details: System.Data.SqlClient.SqlException:
Line 1: Incorrect syntax near '.'.

it seems it doesn't reconize the convert.ToString(number1)
I use C#.

Is there other way to do it,

thanks again.

haiwen


>-----Original Message-----
>try convert.ToString(number1) + convert.ToString(number2).
>
>if you want to convert the result to a number then wrap

the above command
>around a
>
>convert.ToInt64 command.
>
>hope this helps, let me know!
>
>
>
>"haiwen" <(E-Mail Removed)> wrote in message
>news:022301c34d6d$df36a420$(E-Mail Removed)...
>> hello, everyone:
>>
>> we can concate two strings when changing column name,

such
>> as: select firstname +' ' + lastname as name from user;
>>
>> but how can I concate two intergers(treat them as

strings)?
>> when I use +, I alway get the result of addition.
>>
>> Thanks
>>
>> haiwen

>
>
>.
>

 
Reply With Quote
 
Tom Vande Stouwe MCSD.net
Guest
Posts: n/a
 
      18th Jul 2003
that goes in the SQL statement. It is processed by SQL, not .net

--
==========================================
= Tom Vande Stouwe MCSD.net, MCAD.net, MCP
= 45Wallstreet.com (www.45wallstreet.com)
= (803)-345-5001
==========================================
= If you are not making any mistakes
..= ..you are not trying hard enough.
==========================================
"haiwen" <(E-Mail Removed)> wrote in message
news:04c601c34d74$1f54ebb0$(E-Mail Removed)...
> hi, thank you for your help.
>
> I try it, but I get the exception:
>
> Exception Details: System.Data.SqlClient.SqlException:
> Line 1: Incorrect syntax near '.'.
>
> it seems it doesn't reconize the convert.ToString(number1)
> I use C#.
>
> Is there other way to do it,
>
> thanks again.
>
> haiwen
>
>
> >-----Original Message-----
> >try convert.ToString(number1) + convert.ToString(number2).
> >
> >if you want to convert the result to a number then wrap

> the above command
> >around a
> >
> >convert.ToInt64 command.
> >
> >hope this helps, let me know!
> >
> >
> >
> >"haiwen" <(E-Mail Removed)> wrote in message
> >news:022301c34d6d$df36a420$(E-Mail Removed)...
> >> hello, everyone:
> >>
> >> we can concate two strings when changing column name,

> such
> >> as: select firstname +' ' + lastname as name from user;
> >>
> >> but how can I concate two intergers(treat them as

> strings)?
> >> when I use +, I alway get the result of addition.
> >>
> >> Thanks
> >>
> >> haiwen

> >
> >
> >.
> >



 
Reply With Quote
 
John
Guest
Posts: n/a
 
      20th Jul 2003
Select cast(col1 as varchar) + cast(col2 as varchar) from table1

John
http://mallsocket.com

"haiwen" <(E-Mail Removed)> wrote in message
news:022301c34d6d$df36a420$(E-Mail Removed)...
> hello, everyone:
>
> we can concate two strings when changing column name, such
> as: select firstname +' ' + lastname as name from user;
>
> but how can I concate two intergers(treat them as strings)?
> when I use +, I alway get the result of addition.
>
> Thanks
>
> haiwen



 
Reply With Quote
 
haiwen
Guest
Posts: n/a
 
      21st Jul 2003
hello,John,

It works well! thanks a lot!

Haiwen
>-----Original Message-----
>Select cast(col1 as varchar) + cast(col2 as varchar) from

table1
>
>John
>http://mallsocket.com
>
>"haiwen" <(E-Mail Removed)> wrote in message
>news:022301c34d6d$df36a420$(E-Mail Removed)...
>> hello, everyone:
>>
>> we can concate two strings when changing column name,

such
>> as: select firstname +' ' + lastname as name from user;
>>
>> but how can I concate two intergers(treat them as

strings)?
>> when I use +, I alway get the result of addition.
>>
>> Thanks
>>
>> haiwen

>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using integers within a For Each statement VB.NET tcropper@gmail.com Microsoft ASP .NET 18 22nd May 2009 06:56 PM
Using integers within a For Each statement VB.NET tcropper@gmail.com Microsoft ASP .NET 0 20th May 2009 05:07 PM
Select Integers only =?Utf-8?B?Q2F0aHk=?= Microsoft Access Queries 4 5th Mar 2007 01:08 PM
What function to select the last 3 smallest integers? =?Utf-8?B?RXJpYw==?= Microsoft Excel Worksheet Functions 2 31st Dec 2005 01:39 PM
SELECT procedure - ALL for integers Arek Microsoft ADO .NET 6 18th Oct 2004 11:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:22 AM.