Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 concatenate parameter in select query

Author  Topic 

jtwork
Yak Posting Veteran

82 Posts

Posted - 2007-09-26 : 10:04:32
in the select part of my query i want to provide a column like so

1-5

The parameters for the criteria's are varchar as the help files suggest that i cannot cast a int to text.

I cant get the below to work through...any ideas??

cast(@Min_Criteria as text) + '-' + cast(@Max_Criteria as text) as Criteria

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-26 : 10:09:24

cast(@Min_Criteria as text) + '-' + cast(@Max_Criteria as text) as Criteria

should be


cast(@Min_Criteria as varchar(20)) + '-' + cast(@Max_Criteria as varchar(20)) as Criteria

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rekiller
Starting Member

31 Posts

Posted - 2007-09-26 : 10:10:08
[code]
declare @min_criteria int
declare @max_criteria int
set @min_criteria=1
set @max_criteria=5

select cast(@min_criteria as varchar(10))+'-'+cast(@max_criteria as varchar(10)) as Result

[/code]

Or

[code]

declare @min_criteria int
declare @max_criteria int
declare @result varchar(10)
set @min_criteria=1
set @max_criteria=5

set @result=cast(@min_criteria as varchar(10))+'-'+cast(@max_criteria as varchar(10))
select @result

[/code]


Does this help?

quote:
Originally posted by jtwork

in the select part of my query i want to provide a column like so

1-5

The parameters for the criteria's are varchar as the help files suggest that i cannot cast a int to text.

I cant get the below to work through...any ideas??

cast(@Min_Criteria as text) + '-' + cast(@Max_Criteria as text) as Criteria

Go to Top of Page

jtwork
Yak Posting Veteran

82 Posts

Posted - 2007-09-26 : 10:15:05
Many thanks all
Go to Top of Page
   

- Advertisement -