sql server - LIKE statement with Table variable -


i want selectstatement 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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -