473,488 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Convert Text to int but output as text

1 New Member
I want add a number to a text value and have it appear in
output. Original value column Extension is a text that I
want to add 2100, but I want to have it output to a text.

Using Northwind database, table Employees:

Expand|Select|Wrap|Line Numbers
  1. Select 
  2.   (E.EmployeeID) as 'EmployeeID_ab',
  3.   (E.Extension)  as 'Extension_ab' 
  4. From Employees E
Returns rows like this:
Expand|Select|Wrap|Line Numbers
  1. EmployeeID_ab  Extension_ab
  2.      1           5467
  3.      2           3457
I want rows like this after adding 2100:
Expand|Select|Wrap|Line Numbers
  1. EmployeeID_ab  Extension_ab
  2.      1           7567
  3.      2           5557
Dec 14 '12 #1
3 2301
NeoPa
32,556 Recognized Expert Moderator MVP
I doubt that's true. The syntax for the SQL appears wrong to me in that the ALIAS commands (abbreviated to as in your case) use string literals instead of valid names.

You're probably looking for :
Expand|Select|Wrap|Line Numbers
  1. SELECT CAST(E.EmployeeID AS int) + 2100 AS [EmployeeID_ab]
  2.      , CAST(E.Extension AS int) + 2100 AS [Extension_ab]
  3. FROM   Employees AS E
Dec 14 '12 #2
Rabbit
12,516 Recognized Expert Moderator MVP
In SQL Server, it is valid to put the alias in quotes.

If you want the final result to be a text data type, take what NeoPa did and put another cast around the expression and cast it back to text.
Dec 14 '12 #3
NeoPa
32,556 Recognized Expert Moderator MVP
Rabbit:
In SQL Server, it is valid to put the alias in quotes.
My bad. Rabbit is far more experienced than I am in SQL Server as I no longer have one to work on even, so if he says I'm wrong, then the chances are pretty high that I am.

He is also correct that I overlooked your clear request to convert it back to Text afterwards. I was only thinking of it displaying on the screen, but that wasn't the question. So :
Expand|Select|Wrap|Line Numbers
  1. SELECT CAST(CAST(E.EmployeeID AS int) + 2100, AS nvarchar) AS [EmployeeID_ab]
  2.      , CAST(CAST(E.Extension AS int) + 2100, AS nvarchar) AS [Extension_ab]
  3. FROM   Employees AS E
Dec 14 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3017
by: Oleg Ogurok | last post by:
Hi all, On my web page, I have a <OBJECT DATA="mydatafile.ica" ...> which loads Citrix ICA web client. The problem is that I want to generate the mydatafile.ica on the fly (e.g. based on...
1
5776
by: Thilo-Alexander Ginkel | last post by:
Hello, I am currently trying to assign some string to a TEXT output parameter of a stored procedure. The basic structure of the stored procedure looks like this: -- 8< -- CREATE PROCEDURE...
1
4782
by: noleander | last post by:
Hi. I've got a C++ program written in Visual C++ 2003. The program is trivial, created with the Program-creation wizard: used the .NET "Form" template. The program has a trivial...
10
8008
by: Nikolay Petrov | last post by:
How can I convert DOS cyrillic text to Unicode
6
20592
by: Al | last post by:
Hi Is there any what to convert content of a richTexBoxt from rtf to text? thanks Al
5
9603
by: Socrates | last post by:
I am interested in developing an online utility that will enable users to copy and past any image (or upload any image on the internet) to the online utility, which will then convert the image to...
2
3924
by: bravo | last post by:
hi is there any solution to this problem???? is it possible to convert the output of a jsp page into a image file??? any views?/// ideas???
2
1612
by: Ambika1 | last post by:
I need to convert HTMl into plain text output in vb.net. Can anyone please tell me how can I transform HTML into plain text with an example. Thanks
0
10704
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
7108
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7142
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
272
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.