sql server - LIKE statement with Table variable -
i want select
statement using values have in table variable.
declare @emailids table (usrmst_id int) declare @actionids table (tskmst_id int) insert @emailids (usrmst_id) select usrmst_id usrmst usrmst_domain = 'email' insert @actionids (tskmst_id) select tm.tskmst_id tskmst tm inner join tskmail tml on tml.tskmail_id = tm.tskmst_id tskmail_to_int '%' + (select cast(usrmst_id char(5)) @emailids) + '%' select * @actionids
this failing because select cast(usrmst_id char(5)) @emailids
has multiple results. want each value in @emailids
table generate return @actionids
table.
you can try using inner join
instead:
insert @actionids (tskmst_id) select tm.tskmst_id tskmst tm inner join tskmail tml on tml.tskmail_id = tm.tskmst_id inner join @emailids e on tskmail_to_int '%' + cast(e.usrmst_id varchar(5)) + '%'
you should cast
varchar
instead of char
. believe casting char
pads strings spaces until reaches defined length. when cast
60 char(5)
, becomes 60[space][space][space]
.
Comments
Post a Comment