| Author |
Topic |
|
Nuno1340
Starting Member
6 Posts |
Posted - 2008-02-28 : 06:54:39
|
HelloFirst post here and am looking for some help with a issue I have with concatenation.I am looking to concatenate two columns together into one new column...ins_type + currencyI have searched for help onthis but for some reason nothing I do works...Any ideas or suggestions?ThanksNunoSELECTa.deal_tracking_num AS TemplateDealNum,a.tran_num AS TemplateTranNum,a.reference AS TemplateName,a.ins_type,a.currency,a.trade_date AS TemplateCreated,u.template_tran_num as MiscFROMab_tran a, USER_restricted_templates uWHEREa.tran_type = 0 ANDa.asset_type = 2 ANDa.current_flag = 1 ANDa.toolset IN (33,36,15,16) ANDa.tran_status = 15 ANDa.tran_num *= u.template_tran_num |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2008-02-28 : 07:01:52
|
What data types are they?If ins_type is a number and currency is a char, you would do:select convert(varchar(10),ins_type) + '' + currency |
 |
|
|
readysetstop
Posting Yak Master
123 Posts |
Posted - 2008-02-28 : 07:02:10
|
| If you can't do this in the front end app, try CAST.____________________________________________________________________________________"Believe in those who are seeking the truth. Doubt those who say they have found it." -Andre Gide |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-28 : 07:41:15
|
| <<I am looking to concatenate two columns together into one new column...>>Where do you want to show your data?MadhivananFailing to plan is Planning to fail |
 |
|
|
Nuno1340
Starting Member
6 Posts |
Posted - 2008-02-28 : 08:50:06
|
quote: Originally posted by RickD What data types are they?If ins_type is a number and currency is a char, you would do:select convert(varchar(10),ins_type) + '' + currency
both are numbers... thank you |
 |
|
|
Nuno1340
Starting Member
6 Posts |
Posted - 2008-02-28 : 08:52:15
|
quote: Originally posted by madhivanan <<I am looking to concatenate two columns together into one new column...>>Where do you want to show your data?MadhivananFailing to plan is Planning to fail
an additional column at the end of the query... if that makes sense |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-02-28 : 08:54:10
|
| [code]select cast(cast(ins_type as varchar(5)) + cast(currency as varchar(5)) as int)[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
Nuno1340
Starting Member
6 Posts |
Posted - 2008-02-28 : 09:03:04
|
quote: Originally posted by harsh_athalye
select cast(cast(ins_type as varchar(5)) + cast(currency as varchar(5)) as int) Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED"
thanks... when i try this i get an error message asking for a FROM clause...SELECTa.deal_tracking_num AS TemplateDealNum,a.tran_num AS TemplateTranNum,a.reference AS TemplateName,a.ins_type,a.currency,a.trade_date AS TemplateCreated,u.template_tran_num as Miscselect cast(cast(ins_type as varchar(5)) + cast(currency as varchar(5)) as int)FROMab_tran a, USER_restricted_templates uWHEREa.tran_type = 0 ANDa.asset_type = 2 ANDa.current_flag = 1 ANDa.toolset IN (33,36,15,16) ANDa.tran_status = 15 ANDa.tran_num *= u.template_tran_num |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-02-28 : 09:05:15
|
quote: Originally posted by Nuno1340
quote: Originally posted by harsh_athalye
select cast(cast(ins_type as varchar(5)) + cast(currency as varchar(5)) as int) Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED"
thanks... when i try this i get an error message asking for a FROM clause...SELECTa.deal_tracking_num AS TemplateDealNum,a.tran_num AS TemplateTranNum,a.reference AS TemplateName,a.ins_type,a.currency,a.trade_date AS TemplateCreated,u.template_tran_num as Misc,select cast(cast(ins_type as varchar(5)) + cast(currency as varchar(5)) as int) as SomeColFROMab_tran a, USER_restricted_templates uWHEREa.tran_type = 0 ANDa.asset_type = 2 ANDa.current_flag = 1 ANDa.toolset IN (33,36,15,16) ANDa.tran_status = 15 ANDa.tran_num *= u.template_tran_num
Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-02-28 : 09:06:57
|
| You should really write your joins using ANSI syntax. Express the *= as a LEFT OUTER JOIN. You code is clearer, standard, and easier to maintain.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
Nuno1340
Starting Member
6 Posts |
Posted - 2008-02-28 : 09:09:07
|
quote: Originally posted by harsh_athalye
quote: Originally posted by Nuno1340
quote: Originally posted by harsh_athalye
select cast(cast(ins_type as varchar(5)) + cast(currency as varchar(5)) as int) Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED"
thanks... when i try this i get an error message asking for a FROM clause...SELECTa.deal_tracking_num AS TemplateDealNum,a.tran_num AS TemplateTranNum,a.reference AS TemplateName,a.ins_type,a.currency,a.trade_date AS TemplateCreated,u.template_tran_num as Misc,select cast(cast(ins_type as varchar(5)) + cast(currency as varchar(5)) as int) as SomeColFROMab_tran a, USER_restricted_templates uWHEREa.tran_type = 0 ANDa.asset_type = 2 ANDa.current_flag = 1 ANDa.toolset IN (33,36,15,16) ANDa.tran_status = 15 ANDa.tran_num *= u.template_tran_num
Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED"
i get:Query FailedFatal Database ErrorUnknown Database Error (156)Incorrect syntax near the keyword 'select' |
 |
|
|
Nuno1340
Starting Member
6 Posts |
Posted - 2008-02-28 : 09:12:05
|
quote: Originally posted by jsmith8858 You should really write your joins using ANSI syntax. Express the *= as a LEFT OUTER JOIN. You code is clearer, standard, and easier to maintain.- Jeffhttp://weblogs.sqlteam.com/JeffS
very new to this sql world but will take note of your suggestions |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2008-02-28 : 09:26:42
|
You are using SQL Server, aren't you?!?SELECTa.deal_tracking_num AS TemplateDealNum,a.tran_num AS TemplateTranNum,a.reference AS TemplateName,a.ins_type,a.currency,a.trade_date AS TemplateCreated,u.template_tran_num as Misc,cast(cast(ins_type as varchar(5)) + cast(currency as varchar(5)) as int) as SomeColFROM ab_tran aleft join USER_restricted_templates u on a.tran_num = u.template_tran_numWHEREa.tran_type = 0 ANDa.asset_type = 2 ANDa.current_flag = 1 ANDa.toolset IN (33,36,15,16) ANDa.tran_status = 15 AND |
 |
|
|
|