0

I have two views like below

create view penord1_view 
as
    select 
        ser, docno, pcode, barcode, pname, unid, unit, qty, rate 
    from 
        sale 
    where    
        tc = 'O01' and docdt > @xdate1 and docdt < @xdate2

    union 

    select 
        sser as ser, sdocno as docno, pcode, barcode, pname, unid, unit, qty, rate 
    from     
        sale 
    where 
        tc = 'P01' and docdt > @xdate1 and docdt < @xdate2

and the second one is

create view penord_view 
as
    select 
        ser, docno, pcode, barcode, pname, unid, unit, rate, 
        SUM(qty) AS qty 
    from 
        penord1_view 
    group by 
        ser, docno, pcode, barcode, pname, unid, unit, rate 

The problem is that I cannot pass @xdate1 parameter in the first view.

Please suggest how to do this in a view or in some other way in SQL Server

4
  • Why pass any parameters? You could return the docdt field from the first view and add WHERE statement in the second view Commented Sep 27, 2016 at 9:24
  • docdt cannot be returned from the first view because i cannot sum using docdt Commented Sep 27, 2016 at 9:47
  • even i cannot use function in view ....can i use a scaler function in view ? Commented Sep 27, 2016 at 9:50
  • You can use a table-valued function in a view, that's their main usage. What did you try? And why do you want parameters in the first place? Just expose docdt, filter by it and then don't include it in GROUP BY or SUM Commented Sep 27, 2016 at 10:20

1 Answer 1

1

A view has no parameters by definition. You can see it as a saved query. If you would like to use parameters you should look into using stored procedures.

Sign up to request clarification or add additional context in comments.

2 Comments

Functions, not stored procedures. Functions can be used in queries while stored procedures can't
you may also use a table valued function which will look like a paramete view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.