I want to concatonate the following into ColumnReference
ColumnA + ColumnB + ColumnC + ColumnD
Each of these columns A-D may be variable in length, (but would never
exceed the position in the string I have provided). I would like to store
the values in ColumnReference in the following manner.
ColumnA always begins at position1
ColumnB always begins at position 9
ColumnC always begins at position 13
ColumnD always begins at position 20
Thanks !Rob,
Essentially you need to pad with spaces (unless you wanted other
characters), truncate to length required and concatenate, as in
select ColumnReference =
left((ColumnA + replicate (' ', 8)), 8) +
left((ColumnB + replicate (' ', 4)), 4) +
left((ColumnC + replicate (' ', 7)), 7) +
left((ColumnD + replicate (' ', x)), x)
Replace x with appropriate value (you did not supply the ending position of
ColumnD). Note that the first parameter of the replicate() fn is a space
char (might go unnoticed). I am also assuming all four columns are of the
char family; if not convert as appropriate.
Hope this helps,
Raj
"Rob" <rwc1960@.bellsouth.net> wrote in message
news:yT3ke.18258$J25.12328@.bignews6.bellsouth.net...
>I want to concatonate the following into ColumnReference
> ColumnA + ColumnB + ColumnC + ColumnD
> Each of these columns A-D may be variable in length, (but would never
> exceed the position in the string I have provided). I would like to store
> the values in ColumnReference in the following manner.
> ColumnA always begins at position1
> ColumnB always begins at position 9
> ColumnC always begins at position 13
> ColumnD always begins at position 20
> Thanks !
>|||You can pad and concatenate strings in SQL, but a better question is
why are you destroying and doing formatting in the database?
Showing posts with label variable. Show all posts
Showing posts with label variable. Show all posts
Monday, March 12, 2012
Wednesday, March 7, 2012
How to compare dynamic variable in proc
I have a table with 52 columns named 'Week1', 'Week2' etc. with values 1, 0 etc. I want to check values in each column. I have following lines in my procedure.
Declare @.l_str varchar(50),
@.l_count int
Select @.l_count = 1
Select @.l_str = 'Week' + Convert(varchar, @.l_count)
Now how do I compare the value stored in the @.l_str which should be wither 0 or 1 and not 'Week1'?
Is there any better method to compare read these 52 table variables?
Thanks in advanceCompare with what?|||Compare to check what does Week1 holds 1 or 0?|||I have a table with 52 columns named 'Week1', 'Week2' etc. with values 1, 0 etc.
It may be the liquid lunch, but
BBBBBBBBBWWWWWWWWWWWWWWWWWAAAAAAAAAAAAHHHAAHAHAHA
Declare @.l_str varchar(50),
@.l_count int
Select @.l_count = 1
Select @.l_str = 'Week' + Convert(varchar, @.l_count)
Now how do I compare the value stored in the @.l_str which should be wither 0 or 1 and not 'Week1'?
Is there any better method to compare read these 52 table variables?
Thanks in advanceCompare with what?|||Compare to check what does Week1 holds 1 or 0?|||I have a table with 52 columns named 'Week1', 'Week2' etc. with values 1, 0 etc.
It may be the liquid lunch, but
BBBBBBBBBWWWWWWWWWWWWWWWWWAAAAAAAAAAAAHHHAAHAHAHA
Subscribe to:
Posts (Atom)