Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

T SQL Select a Constant Value and Concatenate with another Field

Posted on 2016-09-20
13
Medium Priority
?
69 Views
Last Modified: 2016-09-26
I am using a proprietary front end application to connect to a SQL Server database.
I want to pad a field with a constant string, by using the code below it works with one minor issue * see below:

SELECT (VAL("123456")+Customer.CustomerID FROM Customer

The return value inserts commas every third character:
123,456,555,555,555,555

I tried a few different changes to the syntax but still getting the same results.   The application I use to connect to the SQL Server Database isn't easy to work with - so it is quite a challenge.  Thanks for any info.
0
Comment
Question by:fjkaykr11
[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
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 11

Assisted Solution

by:HuaMinChen
HuaMinChen earned 332 total points
ID: 41807996
Use money if you need comma to the displayed column, like
SELECT CONVERT(varchar, CAST(987654321 AS money), 1)

Open in new window

0
 
LVL 49

Accepted Solution

by:
PortletPaul earned 1004 total points
ID: 41807998
you do NOT want commas?
 so you want to treat the result as a string....

SELECT '123456' + Customer.CustomerID AS StringID
FROM Customer
0
 
LVL 3

Author Comment

by:fjkaykr11
ID: 41808031
Paul thanks for the reply, sorry for the confusion.  That is correct I do not want commas in the return value.
I would like it to be displayed as 123456555555555  instead of 123,456,555,555,555
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 11

Expert Comment

by:HuaMinChen
ID: 41808035
Try
SELECT replace((VAL("123456")+Customer.CustomerID,',','') FROM Customer

Open in new window

0
 
LVL 53

Assisted Solution

by:Ryan Chong
Ryan Chong earned 332 total points
ID: 41808045
what's the format of Customer.CustomerID ?

what Paul commented in ID: 41807998 should return the result you wanted?
1
 
LVL 27

Assisted Solution

by:Zberteoc
Zberteoc earned 332 total points
ID: 41808698
Use this:
SELECT '123456'+cast(Customer.CustomerID AS VARCHAR(25)) AS concat_value FROM Customer

Open in new window

0
 
LVL 3

Author Comment

by:fjkaykr11
ID: 41809809
thanks for all the replies. I might not be able to do this as many functions do not work
in the app I am using (get a lot of errors), including with CAST.
when I tried something like this:
SELECT '123456'+convert(text,18,Customer.CustomerID) AS concat_value FROM Customer
it will bring return a value without errors but still getting the same results (commas after every 3rd character), String did the same.  Using VarChar brings back less values and still has the commas.  I think I will close this out.  Thanks again.
0
 
LVL 3

Author Closing Comment

by:fjkaykr11
ID: 41809813
Thanks
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 41810652
Why using CAST to text? Nobody posted that. text as data type is obsolete in SQL server you what I posted, CAST to VARCHAR(size)...
0
 
LVL 3

Author Comment

by:fjkaykr11
ID: 41813344
I tried that method, it didn't work.    I am not using SSMS.   Thanks again.
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 41816021
Can you be a bit more specific? Didn't work is not enough, code sample that you ran with error massage would be.
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 41816024
Sorry, I just saw that the question had been answered.
0
 
LVL 3

Author Comment

by:fjkaykr11
ID: 41817092
no worries, thanks for the assistance.
0

Featured Post

Independent Software Vendors: 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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

636 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