sql - Alternative to calling stored procedure in a view? -


i created query looking @ transaction information. time period criteria conditional - on 5th of month, needs @ days 16-last day of previous month. on 20th of month, needs @ days 1-15 of same month. run automatically. fine gentleman or woman on stack overflow gave me following stored procedure use, worked perfectly:

declare @today smalldatetime, @start smalldatetime, @end smalldatetime;  set @today = dateadd(day, 0, datediff(day, 0, current_timestamp));  set @start = dateadd(day, 1-day(@today), @today);  set @end = dateadd(day, 15, @start);    if datepart(day, @today) <= 15  begin          set @start = dateadd(month, -1, @end);          set @end = dateadd(day, 1-day(@today), @today);  end     select ... h.billed_date >= @start , h.billed_date < @end;  

now want converted view can access 3rd party data integration tool. google tells me views can't call stored procedures in sql server. dba said whole query converted stored procedure. how convert query sp can accessed data integration tool? here's simplified version of query.

select   c.customer_name , cc.category_name , h.acct_bal     customer c inner join htransactions h on c.customer_id = h.customer_id left outer join customer_category cc on cc.category_id = c.category_id  h.billed date >= @start , h.billed date < @end 

thanks. i'm business analyst trying better @ sql. foundational querying sql getting stronger. need transistion learning more variables , stored procedures.

if needs stored procedure, then:

create procedure dbo.pulldata -- whatever begin     set nocount on;      declare @today smalldatetime, @start smalldatetime, @end smalldatetime;       set @today = dateadd(day, 0, datediff(day, 0, current_timestamp));      set @start = dateadd(day, 1-day(@today), @today);      set @end = dateadd(day, 15, @start);        if datepart(day, @today) <= 15      begin              set @start = dateadd(month, -1, @end);              set @end = dateadd(day, 1-day(@today), @today);      end         select ... h.billed_date >= @start , h.billed_date < @end;  end go 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -