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

x
?
Solved

sql - alter field in select statement

Posted on 2011-09-21
4
Medium Priority
?
235 Views
Last Modified: 2012-05-12
How do I take the following statement...

select glg_budg_dtl.gl_bud_idx,  glg_budg_dtl.gl_bud_cd from glg_budg_dtl

Result  
1,TR
2,BD

and make it return

01, TR
02,BD

basically changing the first returned field from a number to text and prepending a "0"
All values are below 10
0
Comment
Question by:KeithMcElroy
[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
4 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 1000 total points
ID: 36575965
select '0' + convert(varchar,glg_budg_dtl.gl_bud_idx) as gl_bud_idx,  glg_budg_dtl.gl_bud_cd
from glg_budg_dtl
0
 
LVL 14

Assisted Solution

by:Christopher Gordon
Christopher Gordon earned 1000 total points
ID: 36575981
What would you expect the output to look like when your "value" column reached 10?

Would it be 10, or 010?

Same question for 100?  If your values pass 100, would you expect the output to look like this?

001, 002, 003.

Thanks!
0
 
LVL 14

Expert Comment

by:Christopher Gordon
ID: 36575987
Ah missed your last line.  Please disregard my response.  Sorry!
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 36576068

select '0' + cast(isnull(glg_budg_dtl.gl_bud_idx, 0) as varchar) as gl_bud_idx,  glg_budg_dtl.gl_bud_cd 
from glg_budg_dtl

Open in new window

0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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 …
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
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.

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