Link to home
Start Free TrialLog in
Avatar of Dell12805
Dell12805Flag for United States of America

asked on

SQL Columns

I want to convert this back to one column by concatenating the variables i.e.   (@a1 " & " @a2) can this be done?


DECLARE @A1 VARCHAR(2),
            @A2 VARCHAR(2),
            @A3 VARCHAR(2),
            @A4 VARCHAR(2),
            @A5 VARCHAR(2),
            @A6 VARCHAR(2)



SELECT SUBSTRING (LottoNum,1, 2) AS A1, SUBSTRING (LottoNum,3, 2) AS A2,SUBSTRING (LottoNum,5, 2) as A3,SUBSTRING (LottoNum,7, 2) AS A4,
SUBSTRING (LottoNum,9, 2) AS A5, SUBSTRING (LottoNum,11, 2) AS A6
     
FROM [Lotto].[dbo].[LottoAccount]
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

your code does not fill @a1 etc ...

SELECT @a1 = SUBSTRING (LottoNum,1, 2) AS A1,  etc ...

as from then, you can do :
set @result = @a1 + @a2 ... etc ..
Avatar of Bill Prew
Bill Prew

In this particular example you could of course do this as well.

SELECT @result = SUBSTRING(LottoNum,1, 12) FROM [Lotto].[dbo].[LottoAccount]

That may not work if you to take the data from the vars rather than the table, but since the pieces were contiguous in the original field this could be an alternate approach.

~bp
Avatar of Dell12805

ASKER

This did not work.

DECLARE @A1 VARCHAR(2),
        @A2 VARCHAR(2),
            @result VARCHAR(20)

SET @result = @A1 + @A2

SELECT @result = (SUBSTRING (LottoNum,1, 2), SUBSTRING (LottoNum,3, 2))
from dbo.LottoAccount

print @result
I tried this as well Bill

DECLARE @A1 VARCHAR(2),
        @A2 VARCHAR(2),
            @result VARCHAR(20)


SELECT @result = SUBSTRING (LottoNum,1, 2) AS A1, SUBSTRING (LottoNum,3, 2) AS A2
SET @result = @A1 + @A2

from dbo.LottoAccount

print @result
your code does not make much sense so far.
you set @restult, but overwrite it then again ...
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is why I am asking for help :


SELECT @result = SUBSTRING (LottoNum,1, 2) AS A1, SUBSTRING (LottoNum,3, 2) AS A2


from dbo.LottoAccount

print @result
Thanks for your help