gberisha
gberisha

Reputation: 301

SQL fails to convert types, but why

I am trying to filter a query the following way:

declare @CubeYear as varchar(30)
--Setting it this way so it can later be easily used in SSAS Cubes
set @CubeYear = '[Date].[Year].&[2013]'
SELECT [RankingID]
      ,[Year]
      ,[Customer]
      ,[Rank]
FROM [OBase].[dbo].[fact_KundeRanking]
where '[Date].[Year].&[' + Year  + ']' = @CubeYear

but I keep getting the following error:

Conversion failed when converting the varchar value '[Date].[Year].&[2013]' to data type int.

Does anybody know what the solution to this might be?

Upvotes: 0

Views: 38

Answers (1)

Sachin Shanbhag
Sachin Shanbhag

Reputation: 55479

Try this -

where '[Date].[Year].&[' + CAST(Year as varchar(4)) + ']' = @CubeYear

Upvotes: 1

Related Questions