help me to solve the string condition in sql server 2008? -


departmentid   parentid 2          52630     8          52630     14         52630     20         52630     26         52630  declare @retstr varchar(8000)   select top 5 @retstr =  coalesce(@retstr + ',','') +''''+    convert     (varchar,departmentid)    +''''          department  parentid =52630 print @retstr 

i following result

output : '2','8','14','20','26'

@retstr have '2','8','14','20','26' value, using in operator check condition

select * product         inner join [departmentproduct] dp on p.productid=dp.productid         inner join [department] d on d.departmentid = dp.departmentid         inner join [producttranslation] pt on p.productid = pt.productid , pt.localeid = 1                **d.department in (@retstr)** 

it throws following error:

error converting data type nvarchar bigint.

you comparing bigint string in second query. want use subquery instead of saving string.

    select *        product  inner join [departmentproduct] dp on p.productid=dp.productid  inner join [department] d on d.departmentid = dp.departmentid  inner join [producttranslation] pt on p.productid = pt.productid , pt.localeid = 1       d.department in (select top 5 departmentid                               department parentid =52630) 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -