Solved

sql - alter field in select statement

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TSQL - How to declare table name 26 31
SQL View nearest date 5 38
SQL - Update field defined as Text 6 17
Job - date manual 1 23
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…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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 SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

831 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