DECLARE @t TABLE (EMGID Varchar(7), Reference Varchar(8), Backscan Int);INSERT INTO @tSELECT '1267202', '32655185', 1UNION ALL SELECT '1267202', '32655185', 0UNION ALL SELECT '1239667', '33264522', 1UNION ALL SELECT '1239667', '33264522', 1UNION ALL SELECT '1234000', '33674689', 0UNION ALL SELECT '1234000', '33674689', 0;select * from @t twhere exists(select 1 from @t t1 where t1.EMGID = t.EMGID and Backscan = 0) and exists(select 1 from @t t1 where t1.EMGID = t.EMGID and Backscan = 1);
CREATE TABLE Foobar(emg_id VARCHAR(7) NOT NULLCHECK (emg_id LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9]'), vague_reference VARCHAR(8) NOT NULLCHECK (vague_referenceLIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'), something_backscan SMALLINT DEFAULT 0 NOT NULLCHECK (something_backscan IN (0,1));
Msg 102, Level 15, State 1, Line 8Incorrect syntax near ';'.