I'm exporting data from one table (for now) to a fixed width text file.
However, the first column of the text file doesn't come from the
database. I figured using a constant would be the best way to deal with
this, but being new (thrown in) to T-SQL, I'm not sure how to get
there.
The resulting text file has 4 fields, all with fixed character
placement. The first field is an account #, which is the constant field
not in a table. The 2nd field is a 2 character placeholder that's
supposed to be blank, the third a dollar amount, and the 4th a date.
All are to be displayed as a string with no formatting and leading
zeros:
001234567899 00000050006012006
001234567899 00000004306012006...
I can manage individual statements in query analyzer (for fields 2-4),
but I'm clueless about putting it all together in a t-sql statement/dts
package. Any ideas are appreciated.
Thanks,
Not-for-long Newbie and proud of it.Here are two options for using literal values in your SELECT statements.
First choice is good in stored procedures where you don't know the constant
value in advance.
DECLARE @.ConstantValue
SELECT @.ConstantValue = Column_X
FROM MyTable
WHERE {criteria}
SELECT
@.ConstantValue
, Column2
, Column3
, Column4
FROM MyOtherTable
Second Option: (constant value is known is advance)
SELECT
'ConstantValue'
, Column1
, Column3
, Column4
FROM MyOtherTable
--
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."
*Yet Another certification Exam
<birdbyte@.gmail.com> wrote in message news:1151430908.647285.244450@.m73g2000cwd.googlegroup
s.com...
> I'm exporting data from one table (for now) to a fixed width text file.
> However, the first column of the text file doesn't come from the
> database. I figured using a constant would be the best way to deal with
> this, but being new (thrown in) to T-SQL, I'm not sure how to get
> there.
>
> The resulting text file has 4 fields, all with fixed character
> placement. The first field is an account #, which is the constant field
> not in a table. The 2nd field is a 2 character placeholder that's
> supposed to be blank, the third a dollar amount, and the 4th a date.
> All are to be displayed as a string with no formatting and leading
> zeros:
> 001234567899 00000050006012006
> 001234567899 00000004306012006...
>
> I can manage individual statements in query analyzer (for fields 2-4),
> but I'm clueless about putting it all together in a t-sql statement/dts
> package. Any ideas are appreciated.
>
> Thanks,
> Not-for-long Newbie and proud of it.
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment