Solved

sql - alter field in select statement

Posted on 2011-09-21
4
229 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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…

920 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

14 Experts available now in Live!

Get 1:1 Help Now