Results 1 to 8 of 8

Thread: stored procedure sanity check! [resolved]

  1. #1

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Resolved stored procedure sanity check! [resolved]

    Guys, I need a fresh pair of eyes to look at this:


    Code:
    'vbscript
    oConn.execute ("spVan_progress 2, " & session("van_id"))
    'where van_id = 3
    Code:
    'sp
    CREATE PROCEDURE spVan_progress
    (
    @step char(1),
    @ref bigint
    )
    AS declare @sql nvarchar(500)
    
    set @sql = 'update tblVan_counter set q ' + @step + ' = 1 where ref =  ' + @ref
    
    execute sp_execute1 @sql
    GO
    should have the effect of...

    Code:
    spVan_progress 2, 3
    'or
    update tblVan_counter set q2 = 1 where ref = 3
    The step variable is required so I can use the same sp to update any column. It should work (as far as I can see) but I get the error:

    Code:
    Microsoft OLE DB Provider for SQL Server (0x80040E07)
    Error converting data type varchar to bigint.
    The only bigint field in the table is 'ref' which I'm not altering. The q1 (q2, q3 etc) fields are bit.

    Any clues?!
    Last edited by thebloke; May 23rd, 2005 at 09:25 AM. Reason: resolved
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  2. #2
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: stored procedure sanity check!

    Try this:
    Code:
    'sp
    CREATE PROCEDURE spVan_progress
    (
    @step char(1),
    @ref bigint
    )
    AS declare @sql nvarchar(500)
    
    set @sql = 'update tblVan_counter set q ' + @step + ' = 1 where ref =  ' + CAST(@ref AS varchar(10))
    
    execute sp_execute1 @sql
    GO
    And, to be safe, I'd call it like this:
    Code:
    spVan_progress '2', 3

  3. #3

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Re: stored procedure sanity check!

    Nope, still aint working. The CAST got me past the first problem but it's now throwing up this one (whether I put the 2 in single quotes or not....)

    Code:
    'debugging in query analyser
    Server: Msg 170, Level 15, State 1, Line 1
    Line 1: Incorrect syntax near '2'.
    Code:
    'sp now reads:
    
    CREATE PROCEDURE spVan_progress
    (
    @step char(1),
    @ref bigint
    )
    AS declare @sql nvarchar(500)
    
    set @sql = 'update tblVan_counter set q ' + @step + ' = 1 where ref =  ' + CAST(@ref AS varchar(10))
    
    execute sp_executesql @sql
    GO
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  4. #4
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: stored procedure sanity check!

    There's a space after your q in the SQL string.
    Shouldn't be there

    Code:
    set @sql = 'update tblVan_counter set q' + @step + ' = 1 where ref =  ' + CAST(@ref AS varchar(10))

  5. #5

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Resolved Re: stored procedure sanity check!

    Well spotted, that man! Cheers mate. You've saved me from getting blisters on my eyes!

    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: stored procedure sanity check! [resolved]

    Shouldn't it be
    execute @sql
    OR
    sp_executesql @sql
    ???

    I've never seen it done with both in there like that....

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: stored procedure sanity check! [resolved]

    I don't think it matters Tg - don't the system stored procs just have an implicit 'exec' to save you all that typing?

  8. #8

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Re: stored procedure sanity check! [resolved]

    Quote Originally Posted by techgnome
    Shouldn't it be
    execute @sql
    OR
    sp_executesql @sql
    ???

    I've never seen it done with both in there like that....

    Tg
    Can't remember where I found this way, it was ages ago. It works anyway and that'll do for me! I'll give your suggestion a go as anything that saves me typing is always welcomed!

    Cheers guys
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

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