custom SQL in ODBC satge
Moderators: chulett, rschirm, roy
custom SQL in ODBC satge
hi all
i have a table attr_fact where i am storing 52 weeks of history.I want to pull data from that table and put it in a sequential table.I need only 13 weeks(latest 13 weeks) of data.I am having a field week_code in that table which is being populated by look up on time_dim table.time_dim table is a table where for each fiscal date there is a week_code means 365 days are there and for each day corresponding week_code is there.
Fiscal_date week_code
20070101 200701
20070102 200701
....
20070110 200702
.....
like tis..........
week code ranges from 1 to 52/53 for a year..
200701,200702............200752
how can i write a SQL that would ask me data_date as a run time parameter and using that value i ll find the 13 distinct weeks from the time_dim and fetch data for those 13 weeks.
i am able to find the week_code from sysdate by using select (sysdate,'YYYYIW') from dual.but that value is different from the value in the table.So in my SQL i want to refer the table value.
select * from attr_fact where week_code between.........and............
1st blank should give me 13 distinct weeks back to the recent week and second blank will refer to recent week.is it possible to write a subquery there so that it will give the desired result.
[/list]
i have a table attr_fact where i am storing 52 weeks of history.I want to pull data from that table and put it in a sequential table.I need only 13 weeks(latest 13 weeks) of data.I am having a field week_code in that table which is being populated by look up on time_dim table.time_dim table is a table where for each fiscal date there is a week_code means 365 days are there and for each day corresponding week_code is there.
Fiscal_date week_code
20070101 200701
20070102 200701
....
20070110 200702
.....
like tis..........
week code ranges from 1 to 52/53 for a year..
200701,200702............200752
how can i write a SQL that would ask me data_date as a run time parameter and using that value i ll find the 13 distinct weeks from the time_dim and fetch data for those 13 weeks.
i am able to find the week_code from sysdate by using select (sysdate,'YYYYIW') from dual.but that value is different from the value in the table.So in my SQL i want to refer the table value.
select * from attr_fact where week_code between.........and............
1st blank should give me 13 distinct weeks back to the recent week and second blank will refer to recent week.is it possible to write a subquery there so that it will give the desired result.
[/list]
Subselect? select * from your table where somedate between (select startdate from xyz) and (select enddate from xyz)
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Why you want to do custom SQL ?
Use generated SQL and use a constraint in TX..
Use this as constraint in output link.
Use generated SQL and use a constraint in TX..
Code: Select all
sv1=right(in.week_code,2)
sv2= if sv1>38 and sv1<53 then 1 else 0
If women didn't exist, all the money in the world would have no meaning.
-- Aristotle Onassis
-- Aristotle Onassis
i think i didnot explain my requirements clearly..
the time_dim table contains week_code for each fiscal date.
and week code ranges from 200701.......200752,200801......200852 and so on.i need to run the job every month and every month i need latest 13 weeks of data.So its better to write a where condition in the data
the time_dim table contains week_code for each fiscal date.
and week code ranges from 200701.......200752,200801......200852 and so on.i need to run the job every month and every month i need latest 13 weeks of data.So its better to write a where condition in the data
A 2? My first answer rates a 2? Your issue is how to write a query that uses subselect to fetch between values. Do you want me to write the SQL statement FOR you? I don't even know your database or all of your table and column names.
You need to know your current date so that you can compute 13 weeks prior. So, how would you write that SQL?
If you didn't like my first SQL, here's another way:
select * from attr_fact where week_code IN (select week_code from time_dim where time_dim_date between sysdate and sysdate - 13 weeks)
Does this rate higher than a 2?
You need to know your current date so that you can compute 13 weeks prior. So, how would you write that SQL?
If you didn't like my first SQL, here's another way:
select * from attr_fact where week_code IN (select week_code from time_dim where time_dim_date between sysdate and sysdate - 13 weeks)
Does this rate higher than a 2?
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Pass your date in the format YYYYMMDD. Your query will look something like this
NOTE: Query written assuming your working with ORACLE.
Code: Select all
select * from myTable
where week_code between
(SELECT week_code FROM time_dim where
FISCAL_DATE = #dateparam#) AND
(SELECT week_code FROM time_dim where
FISCAL_DATE = TO_CHAR(TO_DATE(#dateparam#,'YYYYMMDD') - (7*13), 'YYYYMMDD'))
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.