Solved

CONVERT Number to String (SQL QueryBuilder)

Posted on 2013-05-28
8
578 Views
Last Modified: 2013-06-02
OK, I need to convert a Number to a String so I can concatenate two fields together.

See attached screen shot

I need to convert the Site Number from Int to String so I can do something like this:

SiteNumber,
SiteName,
SiteNumber + ' - ' + SiteName AS DisplayName

But it won't let me because SiteNumber is a Int and is trying to add it to my dash.

I need something like CAST or CONVERT like used in SQL.

Thanks,
Mark
Query.jpg
0
Comment
Question by:smithmrk
  • 4
  • 4
8 Comments
 
LVL 20

Expert Comment

by:dsacker
ID: 39201902
In SQL it would be:

CONVERT(varchar(10), SiteNumber) + ' - ' + CONVERT(varchar(10), SiteNumber)

In VB.NET it would be

SiteNumber.ToString() + ' - ' + SiteNumber.ToString()
0
 

Author Comment

by:smithmrk
ID: 39201921
Thanks dsacker...but how do I convert it in Query Builder?
This caused an error...see screen shot!

Mark
QueryError.jpg
0
 
LVL 20

Expert Comment

by:dsacker
ID: 39201942
That's your table definition. Your question pertains to querying against it.

I'd leave that alone and simply code your queries accordingly.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:smithmrk
ID: 39201966
I have the data hookup to a DropDownList and want the DisplayMember to show the Site Number and Name together.

Example:
10 - SiteName

In order to do that I need a DisplayMember that has the two fields concatenated together like this:
SiteNumber + ' - ' + SiteName AS DisplayName

It won't let me do this because the SiteNumber is a number and needs to be a string.

Mark
0
 
LVL 20

Expert Comment

by:dsacker
ID: 39201972
In your query is where you want to convert it to a string. Wherever you are doing this:

SiteNumber + ' - ' + SiteName AS DisplayName

Change it to this:

CONVERT(varchar(10), SiteNumber) + ' - ' + SiteName AS DisplayName

It should work for you just fine after that.
0
 
LVL 20

Expert Comment

by:dsacker
ID: 39201980
In your Query Builder, can you change over to SQL view and code it directly in there?
0
 

Accepted Solution

by:
smithmrk earned 0 total points
ID: 39201992
Nevermind...I figured it out

CStr(SiteNumber) + ' - ' + SiteName

Thanks,
Mark
0
 

Author Closing Comment

by:smithmrk
ID: 39214079
Figured it out by testing it in MS Access.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 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