Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 August 14th, 2007, 06:06 AM
Registered User
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to kumar3_99
Default If condition doesn't work else part Please help me

Hi,
I'm kumar.
i have been facing a problem.
please help me.

i have write a stored procedure using if else condition.
in this stored procedure if part perfectly work. but else doesn't work to me.

[u]here is the my stored procedure. please help me.</u>

Code:
CREATE PROCEDURE searchKword1
@kword varchar(50),
@ordBy varchar(20)
AS

create table #tempTest (ThreadID int, CatID int, UserID int, ThreadName varchar(100), creationDate varchar(30), CatName varchar(100))

if @ordBy='Thread.creationDate'
begin

insert #tempTest
select distinct Thread.ThreadID, Thread.CatID, Thread.UserID, Thread.ThreadName, Thread.creationDate, Category.CatName from Category, Thread join Message on Thread.ThreadID=Message.ThreadID where ((Message.BodyText like '%'+@kword+'%' or Thread.ThreadName like '%'+@kword+'%')) and ( (Thread.ThreadID=Message.ThreadID)and (Category.CatID=Thread.CatID) )  order by Thread.creationDate ASC

select count(*) as TotalRecordASC  from #tempTest

drop table #tempTest

end

else if @ordBy='Thread.creationDateDESC'

begin

insert #tempTest
select distinct Thread.ThreadID, Thread.CatID, Thread.UserID, Thread.ThreadName, Thread.creationDate, Category.CatName from Category, Thread join Message on Thread.ThreadID=Message.ThreadID where ((Message.BodyText like '%'+@kword+'%' or Thread.ThreadName like '%'+@kword+'%')) and ( (Thread.ThreadID=Message.ThreadID)and (Category.CatID=Thread.CatID) )  order by Thread.creationDate DESC

select count(*) from #tempTest

drop table #tempTest

end
GO
 
Old August 14th, 2007, 08:53 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

in statements like...
   if @ordBy='Thread.creationDate'
...the string is treated as a literal, not a column from a table,

You need a SELECT in there somewhere.

--Jeff Moden
 
Old August 14th, 2007, 09:21 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I think he meant it to be a string literal to simulate dynamic order by statements?

Maybe it should be this:

else if @ordBy = 'Thread.creationDate DESC'

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old August 14th, 2007, 09:27 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Ah... yeah... Read this too fast. Thanks, Imar.

--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
or condition kgoldvas XSLT 1 July 31st, 2007 03:44 AM
where condition...? mnr555 Crystal Reports 0 June 18th, 2006 05:32 PM
if then else condition mateenmohd Classic ASP Basics 0 April 16th, 2005 07:08 AM
Condition mateenmohd SQL Server 2000 6 May 6th, 2004 03:49 AM
How do I get the QueryDef part to work bhunter Access 0 February 19th, 2004 01:27 PM





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