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 July 1st, 2005, 06:45 AM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default multiple sql statement

Hi there,

i am a starter for SQL server, i wonder someone of you could help me out as i am struggling to execute second select statement based on the first sql statements result.

i have two sql statement, say the first returns the customer record,if i get the result then exit the SP otherwise try for another select statement for an agent.

immediate response will highly be appreciated.

regards
ibs
 
Old July 1st, 2005, 09:13 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

After your first select statement check the @@rowcount variable:

IF @@rowcount > 0
   return
Else
   Run your second query here ....

 
Old July 1st, 2005, 09:44 AM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi jbenson001,

thanks a million ! that work very well for me.

cheers
ibs


 
Old July 1st, 2005, 10:02 AM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can you please also let me know how to handle this from my ASP page, when i try to call this SP , works fine for the first query but when i try to give username/password for the second select statment its not returning nothing on my asp page.

whereas i can see the result returned back in sql-analyser.

could you see my point ?
 
Old July 1st, 2005, 10:08 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I would need to see your code to find out what you are trying to do.

Jim

 
Old July 1st, 2005, 10:27 AM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Jim,

its basically a login page, two types of customers trying to access one single login, say type A,typy B customers.

when tpye A customer try to login, i will be using first select statement which takes username/password and returns back the record, if this query returns nothing than i try for the second statement assuming that this is type B customer, if it matches than return back the record.


it works very fine in Query Analyzer but through ASP page its not,
it is working fine for the first type A , i beleive its only referring to the first select statement all the time.

if this is not cleared, i would than try to post my code then
.

thanks much
ibs








Similar Threads
Thread Thread Starter Forum Replies Last Post
update multiple column based on case statement?? vinod_yadav1919 SQL Server 2000 6 July 3rd, 2008 07:29 PM
multiple updates in one statement rashi Access 1 December 21st, 2007 01:05 AM
convert a SQL Statement from MS Access to a SQL Corey Access 6 March 28th, 2007 12:33 PM
Statement for Multiple Filters in SQL mckly Pro VB Databases 1 August 2nd, 2004 01:53 PM
Refer to multiple databases in one SQL statement JimPaum Pro VB Databases 5 June 25th, 2003 08:57 AM





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