Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 1st, 2008, 10:13 AM
Friend of Wrox
Points: 550, Level: 8
Points: 550, Level: 8 Points: 550, Level: 8 Points: 550, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , , .
Posts: 112
Thanks: 12
Thanked 0 Times in 0 Posts
Default Store procedure help ???

Hi to all...

I created this store procedure that i pass it a 6 digit number...
but it returnes me nothing...

CREATE PROCEDURE sp_GetAllSKU
    @intSKU int

AS
    select * from PromoDetailID PD
    Join PromoID P On P.PromoID = PD.PromoID
    where PD.PromoSKU like '%@varSKU%'
    and P.PromoActive=1
    and P.PromoLanguage='E'

GO

But if i run it in query analyzer and actually put a number it returnes me info...

select * from PromoDetailID PD
Join PromoID P On P.PromoID = PD.PromoID
where PD.PromoSKU like '%417856%'
and P.PromoActive=1
and P.PromoLanguage='E'


Is there something i'm missing in my SP that i need...

thanking you in advance...

Rino

  #2 (permalink)  
Old May 1st, 2008, 10:17 AM
Friend of Wrox
Points: 550, Level: 8
Points: 550, Level: 8 Points: 550, Level: 8 Points: 550, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , , .
Posts: 112
Thanks: 12
Thanked 0 Times in 0 Posts
Default

Sorry don't look at '%@varSKU%' i have it the same as declared @intSKU....

  #3 (permalink)  
Old May 1st, 2008, 10:20 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I would do:
Code:
DECLARE @Search NVARCHAR(20);
SET @Search = '%' + CAST(@intSKU AS NVARCHAR(15)) + '%';
SELECT .... WHERE PD.PromoSKU LIKE @Search....
--

Joe (Microsoft MVP - XML)
  #4 (permalink)  
Old May 1st, 2008, 10:27 AM
Friend of Wrox
Points: 550, Level: 8
Points: 550, Level: 8 Points: 550, Level: 8 Points: 550, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , , .
Posts: 112
Thanks: 12
Thanked 0 Times in 0 Posts
Default

when i apply the SP, it gives me an error "incorrect syntax near '+'"

  #5 (permalink)  
Old May 1st, 2008, 10:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Naperville, IL, USA.
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You had:
Code:
    select * from PromoDetailID PD
    Join PromoID P On P.PromoID = PD.PromoID
    where PD.PromoSKU like '%@varSKU%'
    and P.PromoActive=1
    and P.PromoLanguage='E'
Change it as follows:

    where PD.PromoSKU like '%' + @varSKU + '%'


Rand
  #6 (permalink)  
Old May 1st, 2008, 11:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Naperville, IL, USA.
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oops, one slight difference. Since @varSKU is an integer, you need to do:

WHERE PD.PromoSKU LIKE '%' + CAST(@varSKU AS varchar(10)) + '%'

Rand
  #7 (permalink)  
Old May 1st, 2008, 01:54 PM
Friend of Wrox
Points: 550, Level: 8
Points: 550, Level: 8 Points: 550, Level: 8 Points: 550, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , , .
Posts: 112
Thanks: 12
Thanked 0 Times in 0 Posts
Default

Perfect it works fine...
One other thing not sure if i should post this question in another section...

i have an <input type="text" ... > textbox that has the 6 digits that i need to bring the variable over to my other page and that's where i connect to SQL and run my SP...
it's working fine put returning all rows...
looks like my variable is not coming over with my page...

how can i bring my variable over to another page???

Thanking you in advance

Rino

  #8 (permalink)  
Old May 1st, 2008, 02:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Naperville, IL, USA.
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your other question is more appropriate for a VB, C#, or ASP.NET forum depending upon which you are using.

In other words, I don't know the answer.

:)

Rand
  #9 (permalink)  
Old May 1st, 2008, 03:03 PM
Friend of Wrox
Points: 550, Level: 8
Points: 550, Level: 8 Points: 550, Level: 8 Points: 550, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , , .
Posts: 112
Thanks: 12
Thanked 0 Times in 0 Posts
Default

thank you for your help...



Similar Threads
Thread Thread Starter Forum Replies Last Post
Store procedure help... RinoDM SQL Server 2000 7 August 11th, 2008 07:09 PM
store procedure if else problem krshekhar SQL Language 0 February 20th, 2008 05:31 AM
Create Store Procedure ?? kumiko SQL Language 7 January 4th, 2008 02:11 AM
Store Procedure sureshyuga SQL Server 2000 0 May 18th, 2007 01:49 AM
Store Procedure Problem jazzcatone ASP.NET 2.0 Basics 3 March 28th, 2006 12:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.