Help building dynamic stored procedure

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default Help building dynamic stored procedure

    Hi, I'm in the fianl stages of building a dating app for a client and need a
    little help constructing a stored procedure for an advanced search.

    I've been googling for hours to try and find the right answer but seem to be
    more frustrated than when I started, hers's my scenario

    Here's what I have so far

    ALTER PROCEDURE dbo.TEST_ADVANCED_SEARCH
    (@categoryID int = 0,
    @Age varchar(100) = NULL,
    @locationID int = 0)
    AS
    DECLARE @SQL Varchar (4000)
    SELECT @SQL = 'dbo.user_accounts.profileComplete,
    dbo.user_accounts.categoryID, dbo.user_profiles.locationID,
    dbo.user_profiles.Age
    FROM dbo.user_accounts INNER JOIN
    dbo.user_profiles ON dbo.user_accounts.userID =
    dbo.user_profiles.userID
    WHERE (dbo.user_accounts.profileComplete = 1)'

    IF @categoryID <> 0
    SELECT @SQL = @SQL + ' AND (dbo.user_accounts.categoryID = @categoryID)'

    IF @MAXAGE IS NOT NULL
    SELECT @SQL = @SQL + ' AND (dbo.user_profiles.Age <= @MAXAge) '

    IF @LocationID <> 0
    SELECT @SQL = @SQL + ' AND (dbo.user_profiles.locationID = @locationID)'

    EXEC(@SQL)
    Once I have this running I have a few more fields to add

    Running this query from access .adp file produces an error "Invalid SQL
    Statement - Check the filter on the form record source"
    I think I'm nearly there but just need a not so gentle push in the right
    direction,
    Thanks


    ossie Guest

  2. Similar Questions and Discussions

    1. Stored procedure?
      Stored procedure ?? -- Message posted via http://www.dotnetmonster.com
    2. help with a stored procedure
      I am new to postgres stored procedures and would like a little help. My function basically takes 2 arguments and inserts data into a table from a...
    3. Stored procedure from stored procedure
      Is it possible to create a stored procedure from a stored procedure? When I attempt this inanity, it doesn't blow up until syntax error at the...
    4. Problem building stored procedure
      Hello , I am using DB2 7.2 Personal Edition on Windows NT Workstation 4.0. I need to write stored procedures for DB2. I have installed Application...
    5. Cannot execute dynamic query in stored procedure
      Hi, I'm using ADO.NET to execute a stored proc. The stored proc contains a dynamic sql which will build the INSERT or UPDATE statement for...
  3. #2

    Default Re: Help building dynamic stored procedure

    Ignore the @Age / @MAXAGE Discrepancy,



    "ossie" <fdsg@sdgf.com> wrote in message
    news:d1q9q0$2vm$1@forums.macromedia.com...
    > Hi, I'm in the fianl stages of building a dating app for a client and need
    > a little help constructing a stored procedure for an advanced search.
    >
    > I've been googling for hours to try and find the right answer but seem to
    > be more frustrated than when I started, hers's my scenario
    >
    > Here's what I have so far
    >
    > ALTER PROCEDURE dbo.TEST_ADVANCED_SEARCH
    > (@categoryID int = 0,
    > @Age varchar(100) = NULL,
    > @locationID int = 0)
    > AS
    > DECLARE @SQL Varchar (4000)
    > SELECT @SQL = 'dbo.user_accounts.profileComplete,
    > dbo.user_accounts.categoryID, dbo.user_profiles.locationID,
    > dbo.user_profiles.Age
    > FROM dbo.user_accounts INNER JOIN
    > dbo.user_profiles ON dbo.user_accounts.userID =
    > dbo.user_profiles.userID
    > WHERE (dbo.user_accounts.profileComplete = 1)'
    >
    > IF @categoryID <> 0
    > SELECT @SQL = @SQL + ' AND (dbo.user_accounts.categoryID = @categoryID)'
    >
    > IF @MAXAGE IS NOT NULL
    > SELECT @SQL = @SQL + ' AND (dbo.user_profiles.Age <= @MAXAge) '
    >
    > IF @LocationID <> 0
    > SELECT @SQL = @SQL + ' AND (dbo.user_profiles.locationID = @locationID)'
    >
    > EXEC(@SQL)
    > Once I have this running I have a few more fields to add
    >
    > Running this query from access .adp file produces an error "Invalid SQL
    > Statement - Check the filter on the form record source"
    > I think I'm nearly there but just need a not so gentle push in the right
    > direction,
    > Thanks
    >

    ossie Guest

  4. #3

    Default Re: Help building dynamic stored procedure

    Is this for CF??

    if so try this little toy. [url]http://www.switch-box.org/[/url]


    --
    Bill
    Real Estate Web Sites Made Easy
    [url]www.DataPacks.com[/url]


    "ossie" <fdsg@sdgf.com> wrote in message
    news:d1q9q0$2vm$1@forums.macromedia.com...
    > Hi, I'm in the fianl stages of building a dating app for a client and need
    > a little help constructing a stored procedure for an advanced search.
    >
    > I've been googling for hours to try and find the right answer but seem to
    > be more frustrated than when I started, hers's my scenario
    >
    > Here's what I have so far
    >
    > ALTER PROCEDURE dbo.TEST_ADVANCED_SEARCH
    > (@categoryID int = 0,
    > @Age varchar(100) = NULL,
    > @locationID int = 0)
    > AS
    > DECLARE @SQL Varchar (4000)
    > SELECT @SQL = 'dbo.user_accounts.profileComplete,
    > dbo.user_accounts.categoryID, dbo.user_profiles.locationID,
    > dbo.user_profiles.Age
    > FROM dbo.user_accounts INNER JOIN
    > dbo.user_profiles ON dbo.user_accounts.userID =
    > dbo.user_profiles.userID
    > WHERE (dbo.user_accounts.profileComplete = 1)'
    >
    > IF @categoryID <> 0
    > SELECT @SQL = @SQL + ' AND (dbo.user_accounts.categoryID = @categoryID)'
    >
    > IF @MAXAGE IS NOT NULL
    > SELECT @SQL = @SQL + ' AND (dbo.user_profiles.Age <= @MAXAge) '
    >
    > IF @LocationID <> 0
    > SELECT @SQL = @SQL + ' AND (dbo.user_profiles.locationID = @locationID)'
    >
    > EXEC(@SQL)
    > Once I have this running I have a few more fields to add
    >
    > Running this query from access .adp file produces an error "Invalid SQL
    > Statement - Check the filter on the form record source"
    > I think I'm nearly there but just need a not so gentle push in the right
    > direction,
    > Thanks
    >

    BillB Guest

  5. #4

    Default Re: Help building dynamic stored procedure

    Try logic like

    IF @categoryID <> 0
    SELECT @SQL = @SQL + ' AND (dbo.user_accounts.categoryID =' +
    cast(@categoryID as nvarchar) + ')'


    --
    Jules
    [url]http://www.charon.co.uk/charoncart[/url]
    Charon Cart 3
    Shopping Cart Extension for Dreamweaver MX/MX 2004




    Julian Roberts Guest

  6. #5

    Default Re: Help building dynamic stored procedure

    Thanks for the replys
    I seem to be getting closer, now I get a message saying I must declare the
    variable @categoryID - only when I enter something in the categoryID box, it
    asks for age if there is something in the age box
    fyi site is asp.net VB
    Any more pointers?











    "Julian Roberts" <newsg@charon.co.uk> wrote in message
    news:d1qe1r$8ln$1@forums.macromedia.com...
    > Try logic like
    >
    > IF @categoryID <> 0
    > SELECT @SQL = @SQL + ' AND (dbo.user_accounts.categoryID =' +
    > cast(@categoryID as nvarchar) + ')'
    >
    >
    > --
    > Jules
    > [url]http://www.charon.co.uk/charoncart[/url]
    > Charon Cart 3
    > Shopping Cart Extension for Dreamweaver MX/MX 2004
    >
    >
    >
    >

    ossie Guest

Posting Permissions

  • You may not post new threads
  • You may 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