943,616 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 905
  • MS SQL RSS
Dec 21st, 2007
0

common Question about CustomerID search

Expand Post »
probably, all of you have seen this scenario a lot

when entering customerID into a large database

it takes AGES to bring back one simple record of a single customer

===

let's say, this has been DONE already , for tuning performance

separate the CUSTOMERS table into 2

TBLcustomer1 -- all the customers that got access in the last 2 months (small tables)

TBLcustomer2 -- all the customers in the company (that exclude TBL customer 1)

===== >> obj: without modifying the FORM code or VB/ASP(.net) code etc

Q:
how to write a sql stmt
(i.e. in SQL server level, rather than programming level)
when USER ENTER one customerID for searching


it will first search

select * from TBLcustomer1 -- small talbe

(small table first, if THE CUSTOMER IS FOUND, then exit IF/then for..loop etc, and then all the customers details will be supplied to the program)


IF THE CUSTOMER IS NOT FOUND in the SMALL TABLE

then the program WILL search the much bigger table (this depends on searching on small table)

select * from TBLcustomer2 -- this will take a long time


===== GURU: could you suggest some ways to do it ===

this is very common, I have seen such scenario in ORACLE and SQL server, please kindly propose some viable solution -- I think this could be a Boss-Pleaser (to see instant improve in performance)

Reputation Points: 10
Solved Threads: 0
Newbie Poster
3xxx is offline Offline
19 posts
since Jul 2007
Dec 23rd, 2007
1

Re: common Question about CustomerID search

Hi,

Create a stores procedure (called ex: CustInfo) and forward it the customer code to search for. The body of the procedure will be:
MS SQL Syntax (Toggle Plain Text)
  1. CREATE PROCEDURE CustInfo(@CustCod int) AS
  2.  
  3. IF (SELECT count(*) FROM CustNew WHERE CustNum= @CustCod)>=1
  4.  
  5. SELECT * FROM CustNew WHERE CustNum= @CustCod
  6.  
  7. ELSE SELECT * FROM CustOld WHERE CustNum= @CustCod
  8.  
  9. GO

Then all what you will need to call is the stored procedure with the parameter which varies depending on the programming language you will use (but you can test it in SQL Query analyzer as: CustInfo 236)
Reputation Points: 13
Solved Threads: 29
Junior Poster
kb.net is offline Offline
169 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: ASP and MSSQL : Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
Next Thread in MS SQL Forum Timeline: SQL DB and WebSite





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC