Wrox Programmer Forums
|
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
 
Old May 1st, 2008, 10:13 AM
Friend of Wrox
 
Join Date: Oct 2006
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

 
Old May 1st, 2008, 10:17 AM
Friend of Wrox
 
Join Date: Oct 2006
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....

 
Old May 1st, 2008, 10:20 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old May 1st, 2008, 10:27 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 112
Thanks: 12
Thanked 0 Times in 0 Posts
Default

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

 
Old May 1st, 2008, 10:51 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old May 1st, 2008, 11:13 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old May 1st, 2008, 01:54 PM
Friend of Wrox
 
Join Date: Oct 2006
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

 
Old May 1st, 2008, 02:34 PM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old May 1st, 2008, 03:03 PM
Friend of Wrox
 
Join Date: Oct 2006
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.