Solved

sql - alter field in select statement

Posted on 2011-09-21
4
225 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
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 250 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 250 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:ewangoya
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now