Results 1 to 6 of 6

Thread: View Problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    2

    View Problem

    I am using a inline SQL query in VB which i want to convert to a view in oracle. But the problem is the view also contains search criteria using the where clause and also the group by clause.

    Since it's a pretty long query, I would like to implement it as a VIEW in oracle and just call the view in VB. How do i append the WHERE clause to the VIEW in VB with the group by also there?

    eg IF the view says " Create or replace view EMP_SAL(employees,department,salary) as select employees, department, salary group by department, salary" In VB, I say, select * from SAL_EMP. Now How do I append the where clause in between the query and group by?

    Please shed some light asap.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: View Problem

    How do I append the where clause in between the query and group by?
    You wouldn't. The Where clause would be included in the VB sql statement.

    select * from SAL_EMP Where salary > 10000

  3. #3
    Addicted Member
    Join Date
    Oct 2004
    Location
    Clane, Ireland
    Posts
    179

    Re: View Problem

    I don't know if Oracle is the same as SQL Server, but in SQL Server, you could achieve this by creating a stored procedure, and passing the values of your Where statement as parameters.

    HTH
    JP

    Please rate the postings

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    2

    Re: View Problem

    ya bruce , agreed. But a where clause cannot be appended after a group by. It shd be placed before group by. And the group by is already formed in the view. So how to place the where clause between the query and group by?

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: View Problem

    You don't need to.

    The SQL that 'builds' the view it is irrelevant, as the view is treated like a table by any SQL statements that use it - so just write SQL statements in the usual way, and pretend that the view is a table.

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: View Problem

    What columns do you want to do the WHERE on? Are they already in the VIEW - or did they get lost in the GROUP BY?

    More information please!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width