Solved

Concatenate string in a stored procedures

Posted on 2006-06-28
2
4,911 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

757 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