Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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

Reply With Quote
  #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....

Reply With Quote
  #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)
Reply With Quote
  #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 '+'"

Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
  #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

Reply With Quote
  #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
Reply With Quote
  #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...

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:52 AM.


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