Professional Web Applications Themes

Dynamic WHERE statement - Microsoft SQL / MS SQL Server

Gents, Is there any way this would work, without using the EXEC() command? DECLARE String varchar(100) SET String = 'RoleID = 1' SELECT * FROM dbo.deldlrEmployeeRole WHERE String Thanks in advance, Jaap Terlouw...

  1. #1

    Default Dynamic WHERE statement

    Gents,

    Is there any way this would work, without using the EXEC()
    command?

    DECLARE String varchar(100)
    SET String = 'RoleID = 1'
    SELECT * FROM dbo.deldlrEmployeeRole WHERE String

    Thanks in advance,


    Jaap Terlouw
    Jaap Guest

  2. #2

    Default Re: Dynamic WHERE statement

    For some alternatives refer to :
    http://www.algonet.se/~sommar/dyn-search.html

    --
    - Anith
    ( Please reply to newsgroups only )


    Anith Guest

  3. #3

    Default Re: Dynamic WHERE statement

    See the thread entitled 'append variable' in this group from a few hours
    ago.


    "Jaap Terlouw" <com> wrote in message
    news:01bb01c368e2$df7ffb30$gbl... 


    Aaron Guest

  4. #4

    Default Re: Dynamic WHERE statement

    This will work fine, I don't like to use the exec.l

    Thanks

    DECLARE RoleID int, gRoleID varchar(10)
    SET RoleID = ''

    IF RoleID <> ''
    BEGIN
    SET gRoleID = RoleID
    END
    ELSE
    BEGIN
    SET gRoleID = '%'
    END

    SELECT * FROM dbo.deldlrEmployeeRole WHERE RoleID LIKE
    gRoleID
    jaap Guest

  5. #5

    Default Re: Dynamic WHERE statement

    SELECT * FROM dbo.deldlrEmployeeRole WHERE RoleID = 1;

    --CELKO--
    ===========================
    Please post DDL, so that people do not have to guess what the keys,
    constraints, Declarative Referential Integrity, datatypes, etc. in your
    schema are.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Joe Guest

  6. #6

    Default Re: Dynamic WHERE statement

    I'm not sure I understand. This solution is not solving the same problem
    described in your original post.

    In this case, you know the column name that will be in the WHERE clause; in
    the original question, you were passing in the column name as part of the
    string.

    I love when people say "I need a solution" and when you offer one, they say
    "well I don't like that one." You should have some idea what the
    alternatives are before you ask, and state the one(s) you don't want to
    consider, so that you can prevent others from wasting time offering those
    alternatives.




    "jaap Terlouw" <com> wrote in message
    news:024d01c368e9$dfa99f10$gbl... 


    Aaron Guest

  7. #7

    Default Re: Dynamic WHERE statement

    Jaap Terlouw (com) writes: 

    Of course not.

    --
    Erland Sommarskog, SQL Server MVP, se

    Books Online for SQL Server SP3 at
    http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
    Erland Guest

Similar Threads

  1. dynamic drop downlists in an editable dynamic datagrid.
    By mkhans@gmail.com in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: June 22nd, 09:01 PM
  2. ANN: Learn to go dynamic with WebAssist Dynamic Site 101
    By Joseph Lowery in forum Dreamweaver AppDev
    Replies: 3
    Last Post: April 28th, 04:20 PM
  3. dynamic sql statement with cfqueryparam
    By CF_Greg in forum Coldfusion Database Access
    Replies: 1
    Last Post: April 22nd, 08:24 PM
  4. DYNAMIC Dropdown. How to stick on non dynamic choice?
    By Lesley G in forum Dreamweaver AppDev
    Replies: 3
    Last Post: February 23rd, 05:49 PM
  5. Using a "dynamic top" statement with a cursor
    By Flapper in forum Microsoft SQL / MS SQL Server
    Replies: 4
    Last Post: August 13th, 04:41 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139