Solved

Concatenate string in a stored procedures

Posted on 2006-06-28
2
4,955 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

615 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