sql server - SQL query IF EXISTS -
i want check data exists in table..
my table structure
create table [dbo].[indicatordata] ( [id] [bigint] identity(1,1) not null, [value] [float] not null, [indicatorid] [int] not null, [source] [nvarchar](500) not null, [uploaded] [bit] not null, [createdby] [nvarchar](500) null, [createdon] [datetime] null, [lastmodifiedby] [nvarchar](500) null, [lastmodifiedon] [datetime] null )
table 2
create table [dbo].[datafields] ( [dataid] [bigint] not null, [fieldid] [int] not null )
indicatordata.id
has relationship datafields.dataid
(indicatordata.id
can have multiple combination of datafield)
table indicatordata sample data:
table datafields sample data:
query tried:
note: won't pass dataid, pass field id & indicatorid
scenario #1
select * indicatordata inner join datafields b on a.id = b.dataid a.indicatorid = 72 , b.fieldid in (59, 207)
when pass field id, need combination of values dataid.
output should return this:
kindly suggest how can achive this
does work you?
;with c ( select a.id, cnt = count(*) indicatordata inner join datafields b on a.id=b.dataid a.indicatorid = 72 , b.fieldid in(59,207) group a.id having count(*) > 1 ) select a.*, b.* indicatordata inner join datafields b on a.id=b.dataid inner join c on a.id = c.id;
Comments
Post a Comment