Help on View

  • Hi Guys,

    Does any one know if an argumant(s) can be passed to view in SQL 2000 like date or employee number etc...

    I know for sure in Access we can have a input box for user to enter requested parameter.

     

    Thanks n regards 

    Vikram

  • The parameter in a view is in the where clause.

    select * from myView where SomeCol = 'SomeVal'

  • Thanks Steve for the reply,

    I was looking for a code like create view etc.... similar to what is used in create proc and then we write paramaters shich will be passed to proc.

    If I can get some sample code with create view and how to pass a argument which will be use in select of  that view.

    Appreciate your time.

    regards Vikram

  • I think you're going to need to use a function:

    CREATE FUNCTION dbo.udf_ReturnEmployeeRecordByID(

     @EmployeeID VARCHAR(12)

    &nbsp

    RETURNS @EMPLOYEE_ID TABLE(

     EMPLOYEE_ID VARCHAR(12),

     EMPLOYEE_NAME VARCHAR(100)

    &nbsp

    AS

    BEGIN

    INSERT INTO @EMPLOYEE_ID

     SELECT AD.EMPLOYEEID, AD.PREFERRED_FIRST+' '+AD.PREFERRED_LAST EMPLOYEE_NAME_FULL

     FROM DBO..MYTABLE AD

     WHERE (

     AD.EMPLOYEEID = @EmployeeID

          )

    RETURN

    END

    Syntax for retrieving records is:

    SELECT * FROM DBO.udf_ReturnEmployeeRecordByID('1234)

    HTH:

    MM

  • Thanks Mark,

    I am using function now but it is slow for latger records.

    That's why I was looking to have this via view, I guess I am expecting too much from view .

    regards Vikram

     

  • OYE!!

    VIEWS CAN'T BE PARAMETERISED,

    FOR THIS YOU HAVE TO CREATE A PROCEDURE.

     

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply