Solved

Concatenate string in a stored procedures

Posted on 2006-06-28
2
4,917 Views
Last Modified: 2008-02-01
I need to utilize a concatenate string in a stored procedure.  I have a module in dnn (DotNetNuke) called Enterprise Forms.  It allows me to utilize databinding within a field of a form.  There is a field element option called ‘selectlist’.  This allows me to have a drop down list with a series of options within in it.  With the databinding feature I can have it reference a sql table for the options to be displayed in the ‘selectlist’ element.  The only problem is that the table that I’m referencing has two columns that I need to display in the ‘selectlist’ element.  The developer told me that I can use a concatenate stored procedure to display two columns in one display.  If possible, someone please send me an example.  The table is called 'Products'.    
 
Thanks.
0
Comment
Question by:gopher_49
2 Comments
 
LVL 2

Accepted Solution

by:
PUMASOFT earned 250 total points
ID: 17001789
If both your columns are non numeric, then you just need the + sign...
  SELECT COL1+COL2 AS NEWNAME FROM PRODUCTS

If either of the columns are numeric - then you need to change them using CAST
  SELECT CAST(COL1 AS VARCHAR(10))+COL2 AS NEWNAME FROM PRODUCTS

However in SQL concatenation can default to a varchar(8000) column - which is resource heaver. To avoid this - wrap the whole concatenation in a cast (to be on the safe side).

Here are some examples

  SELECT cast(COL1+COL2 as varchar(50)) AS NEWNAME FROM PRODUCTS


 SELECT cast(CAST(COL1 AS VARCHAR(10))+COL2 as varchar(50)) AS NEWNAME FROM PRODUCTS

 SELECT cast(CAST(COL1 AS VARCHAR(10))+CAST(COL2 AS VARCHAR(10))as varchar(50)) AS NEWNAME FROM PRODUCTS



0
 

Author Comment

by:gopher_49
ID: 17003680
I used the below syntax.

SELECT Column1 + ' ' + Column2 as "Results"
FROM Table 1

thanks...
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now