Solved

Concatenate string in a stored procedures

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

756 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