DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2012
    Posts
    2

    Question Help! How to pass string value into store procedure

    Hi,

    I'm facing a problem, does anyone know how to pass a string value into store procedure? I want to pass the filtering query into store procedure like " where StaffCode between '001' and '005' " in vb6.

    For example,
    CREATE proc SP_Staff
    as
    select * into #TmpTable from Staff (I want pass the string here)
    select * from #TmpTable

    I hope that can get your advise as soon as possible. Thank you.

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,652
    Are you using ADO to connect to your database?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Jun 2012
    Posts
    2
    Hi,

    Yes,I'm using ADO to connect to my database.

    Besides, I have edit my code show as below.
    Code:
    CREATE proc [dbo].[SP_Staff]
    	@Filter varchar(1000)=''
    as
    
    if exists (select  * from tempdb.dbo.sysobjects o where o.xtype in ('U')
       and o.id = object_id(N'tempdb..#TmpTable')) 
    DROP TABLE #TmpTable;
    
    DECLARE @SQLQuery AS VARCHAR(1000)
    DECLARE @SQLQuery1 AS VARCHAR(1000)  
    DECLARE @SQLQuery2 AS VARCHAR(1000) 
    
    SET @SQLQuery = 'select * into #TmpTable From Staff'
    SET @SQLQuery1 = 'order by StaffCode'
    
    IF Len(@Filter) > 0  
    Begin  
    SET @SQLQuery2 = @SQLQuery + ' Where ' + @Filter + @SQLQuery1
    End
    EXECUTE(@SQLQuery2)
    select * from #TmpTable
    
    execute SP_Staff 'StaffCode between 001 and 005'
    It got error "Invalid object name '#TmpTable'" when I execute the store procedure.
    How to solve this error?

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,652
    It looks like you are running a SELECT query against a table you DROPPED
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. Initialise Date type Variable in VB6
    By Lennie in forum VB Classic
    Replies: 9
    Last Post: 11-09-2008, 08:19 PM
  2. App Object
    By Rob Teixeira in forum .NET
    Replies: 15
    Last Post: 05-31-2002, 03:30 PM
  3. Writing in HKEY_LOCAL_MACHINE...Access is denied
    By Martin in forum VB Classic
    Replies: 22
    Last Post: 12-03-2001, 03:53 AM
  4. How do I detect an FTP timeout?
    By Julian Milano in forum VB Classic
    Replies: 0
    Last Post: 08-10-2000, 09:16 PM
  5. Replies: 0
    Last Post: 06-22-2000, 07:30 AM

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
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links