Skip to content

Instantly share code, notes, and snippets.

@swasheck
Created June 12, 2012 19:33
Show Gist options
  • Save swasheck/2919639 to your computer and use it in GitHub Desktop.
Save swasheck/2919639 to your computer and use it in GitHub Desktop.
twonulls sql
declare @test table (
id integer identity(0,1) not null,
dt1 datetime,
dt2 datetime
)
insert into @test (dt1) VALUES (dateadd(DAY, cast((rand() * 100) as int), getdate()))
insert into @test (dt1) VALUES (dateadd(DAY, cast((rand() * 100) as int), getdate()))
insert into @test (dt1) VALUES (dateadd(DAY, cast((rand() * 100) as int), getdate()))
insert into @test (dt1) VALUES (dateadd(DAY, cast((rand() * 100) as int), getdate()))
insert into @test (dt2) VALUES (dateadd(DAY, cast((rand() * 100) as int), getdate()))
insert into @test (dt2) VALUES (dateadd(DAY, cast((rand() * 100) as int), getdate()))
insert into @test (dt2) VALUES (dateadd(DAY, cast((rand() * 100) as int), getdate()))
insert into @test (dt2) VALUES (dateadd(DAY, cast((rand() * 100) as int), getdate()))
insert into @test (dt1,dt2) VALUES (dateadd(DAY, cast((rand() * 100) as int), getdate()),dateadd(DAY, cast((rand() * 100) as int), getdate()))
insert into @test (dt1,dt2) VALUES (dateadd(DAY, cast((rand() * 100) as int), getdate()),dateadd(DAY, cast((rand() * 100) as int), getdate()))
insert into @test (dt1,dt2) VALUES (dateadd(DAY, cast((rand() * 100) as int), getdate()),dateadd(DAY, cast((rand() * 100) as int), getdate()))
insert into @test (dt1,dt2) VALUES (dateadd(DAY, cast((rand() * 100) as int), getdate()),dateadd(DAY, cast((rand() * 100) as int), getdate()))
insert into @test (dt1,dt2) VALUES (NULL,NULL)
insert into @test (dt1,dt2) VALUES (NULL,NULL)
insert into @test (dt1,dt2) VALUES (NULL,NULL)
insert into @test (dt1,dt2) VALUES (NULL,NULL)
select *
from @test
Where (dt1 is not null or dt2 is not null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment