SQL Parameter Label Issue

plucenko
plucenko used Ask the Experts™
on
If I have a Paramater setup for example

declare @Bucket1 integer
set @Bucket1=30

and I have a query

select ABC as  'label' + @Bucket1   from   CBA
I want the label to be...  label 30 ?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
you'll have to cast/convert the int

'label'+ CAST(@Bucket1 AS VARCHAR(10))
declare @bucket integer
declare @label varchar(20)
declare @stmt nvarchar(max)

set @bucket = 30
set @label = 'label' + CONVERT(varchar,@bucket)
set @stmt = N'select abc as ' + @label + ' from cba'

execute sp_executesql @stmt

Author

Commented:
tim_cs - when i run it, I get Incorrect syntax near '+'

Author

Commented:
Tim_cs any ideas?
Steve WalesSenior Database Administrator

Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial