Solved

sql - alter field in select statement

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article I will describe the Copy Database Wizard 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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

739 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