Dell12805
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].[LottoAccoun t]
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].[LottoAccoun
In this particular example you could of course do this as well.
SELECT @result = SUBSTRING(LottoNum,1, 12) FROM [Lotto].[dbo].[LottoAccoun t]
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
SELECT @result = SUBSTRING(LottoNum,1, 12) FROM [Lotto].[dbo].[LottoAccoun
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
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
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
ASKER
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
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 ...
you set @restult, but overwrite it then again ...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
SELECT @result = SUBSTRING (LottoNum,1, 2) AS A1, SUBSTRING (LottoNum,3, 2) AS A2
from dbo.LottoAccount
print @result
ASKER
Thanks for your help
SELECT @a1 = SUBSTRING (LottoNum,1, 2) AS A1, etc ...
as from then, you can do :
set @result = @a1 + @a2 ... etc ..