Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Concatenate string in a stored procedures

Posted on 2006-06-28
2
Medium Priority
?
4,966 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 750 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

660 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