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
 General SQL Server Forums
 New to SQL Server Programming
 concat columns

Author  Topic 

jpockets
Starting Member

45 Posts

Posted - 2007-06-07 : 12:26:30
Hi everyone I'm trying to get 4 columns from my table to be on column, not sure how to go about it.

The column names are
X_POLICY_NO,
X_POLICY_EFCTV_DT,
PRODUCT_ABBR,
X_ASCO_CD

I would like to take those 4 columns in the select statement and make them on, I did in access but I tried

Select
(X_POLICY_NO, X_POLICY_EFCTV_DT, PRODUCT_ABBR, X_ASCO_CD) as CONCAT but i get an error that says :

Incorrect syntax, thanks for the help its greatly appreciated

nr
SQLTeam MVY

12543 Posts

Posted - 2007-06-07 : 12:29:14
X_POLICY_NO + X_POLICY_EFCTV_DT + PRODUCT_ABBR + X_ASCO_CD as CONCAT
you will probably need to cast datatypes
convert(varchar(20),X_POLICY_NO) + convert(varchar(8),X_POLICY_EFCTV_DT,112) + PRODUCT_ABBR + X_ASCO_CD as CONCAT


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

jpockets
Starting Member

45 Posts

Posted - 2007-06-07 : 15:27:45
Thank-you got it working just had a litle problem like you said converting it!!!!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-08 : 09:52:43
Also make sure you handle NULL values

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

mageshks
Yak Posting Veteran

59 Posts

Posted - 2007-06-08 : 23:13:36
You can use CAST too
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-09 : 00:35:19
quote:
Originally posted by mageshks

You can use CAST too

But again you need to handle NULL

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -