Skip to main content

I am new to SQL and have been searching for a way to set variables in ANSI SQL. I have this:

select * from table1
where first_date > ‘2014'2014-01-01'
and where second_date = ‘2014'2014-01-01’01'
and where third_date < ‘2014'2014-01-01’01'

but I am hoping for something like:

set x = ‘2010'2010-12-31’31'
select * from table1
where first_date > x
and where second_date = x
and where third_date < x

I read about stored procedures but it seems like overkill for something so seemingly simple. I'm running on Netezza but I'd like a general solution that can also work on other databases.

I am new to SQL and have been searching for a way to set variables in ANSI SQL. I have this:

select * from table1
where first_date > ‘2014-01-01'
and where second_date = ‘2014-01-01’
and where third_date < ‘2014-01-01’

but I am hoping for something like:

set x = ‘2010-12-31’
select * from table1
where first_date > x
and where second_date = x
and where third_date < x

I read about stored procedures but it seems like overkill for something so seemingly simple. I'm running on Netezza but I'd like a general solution that can also work on other databases.

I am new to SQL and have been searching for a way to set variables in ANSI SQL. I have this:

select * from table1
where first_date > '2014-01-01'
and where second_date = '2014-01-01'
and where third_date < '2014-01-01'

but I am hoping for something like:

set x = '2010-12-31'
select * from table1
where first_date > x
and where second_date = x
and where third_date < x

I read about stored procedures but it seems like overkill for something so seemingly simple. I'm running on Netezza but I'd like a general solution that can also work on other databases.

edited tags
Link
Deduplicator
  • 45.4k
  • 7
  • 71
  • 123
Source Link
slaw
  • 6.7k
  • 17
  • 62
  • 115

Setting a variable in ANSI SQL

I am new to SQL and have been searching for a way to set variables in ANSI SQL. I have this:

select * from table1
where first_date > ‘2014-01-01'
and where second_date = ‘2014-01-01’
and where third_date < ‘2014-01-01’

but I am hoping for something like:

set x = ‘2010-12-31’
select * from table1
where first_date > x
and where second_date = x
and where third_date < x

I read about stored procedures but it seems like overkill for something so seemingly simple. I'm running on Netezza but I'd like a general solution that can also work on other databases.