Click here to Skip to main content
15,906,335 members
Home / Discussions / Database
   

Database

 
GeneralRe: SQL Query - If condition Pin
aaraaayen12-Jun-08 21:38
aaraaayen12-Jun-08 21:38 
GeneralRe: SQL Query - If condition Pin
Ashfield12-Jun-08 21:39
Ashfield12-Jun-08 21:39 
QuestionRestore backup from sql server 2005 to 2000 Pin
PrakashBhaskar12-Jun-08 19:56
PrakashBhaskar12-Jun-08 19:56 
AnswerRe: Restore backup from sql server 2005 to 2000 Pin
Parwej Ahamad12-Jun-08 20:48
professionalParwej Ahamad12-Jun-08 20:48 
AnswerRe: Restore backup from sql server 2005 to 2000 Pin
Mycroft Holmes12-Jun-08 20:49
professionalMycroft Holmes12-Jun-08 20:49 
QuestionError in Mail Triggering Pin
sabaMCA12-Jun-08 11:54
sabaMCA12-Jun-08 11:54 
AnswerRe: Error in Mail Triggering Pin
Parwej Ahamad12-Jun-08 17:43
professionalParwej Ahamad12-Jun-08 17:43 
QuestionSql cursor problem... Pin
tthellebuyck12-Jun-08 4:38
tthellebuyck12-Jun-08 4:38 
Every morning I have a temporary table that gets updated with Customer Sales data (year to date, month to day, last year to date, etc), from another database. One problem I have is that I get every single customer from that database, even if a customer's MTD, YTD,LYTD figures have no changed, resulting in getting 625,000 records. Another is that I need update Existing customer with the data in my temp table. I tried using a while loop and looping through my table to update records. I also tried select the records from the temp table and comparing the values to what is in the existing, the placing those records in a table variable and using a cursor on the temp table. Both of these take entirely too much time. Here is the T-sql for reference...


Declare @ARbal money,
@CustTreeNodeID uniqueidentifier,
@CustomerNumber varchar(50),
@CustomerUpdateID int,
@LYSales money,
@LYTDSales money,
@YTDgm money,
@YTDSales money,
@MTDSales money,
@LMTDSales money

Declare @t table
(
CustomerUpdateID int,
CustomerNumber varchar(50),
YTDSales money,
LYSales money,
ARBal money,
LYTDSales money,
MTDSales money,
LMTDSales money
)

insert into @t(CustomerUpdateID, CustomerNumber,YTDSales, LYSales,ARBal, LYTDsales,MTDSales,LMTDSales)

select CustomerUpdateID,
CustomerNumber,
YTDSales,
LYSales,
ARBal,
LYTDSales,
MTDSales,
LMTDSales
from _CustomerUpdate u

where exists (select 1 from CustTreeNode c join CustTreeNodeaccountAssoc ca on ca.CustTreeNodeID = c.CustTreeNodeID and (u.LYTDSales != ca.LYTD or u.YTDSales != ca.YTD or u.MTDSales!= ca.MTD or u.LMTDSales !=ca.LMTD ))

declare mycursor cursor forward_only
for select CustomerUpdateID from @t

open mycursor
while (1=1)
begin
fetch next from mycursor into @CustomerUpdateID
if @@Fetch_status <>0
break;

set @CustomerNumber = (Select CustomerNumber from _CustomerUpdate where CustomerUpdateID = @CustomerUpdateID)

if isnull(@CustomerNumber,'')<>''
begin
set @CustTreeNodeID =(select CustTreeNodeID from CustTreeNode where CustomerNumber = @CustomerNumber)
end

select top 1 @YTDSales = YTDSales,
@LYSales = LYSales,
@ARbal = ARbal,
@LYTDSales = LYTDSAles,
@MTDSales = MTDSales,
@LMTDSales = LMTDSales
from @t where CustomerUpdateID = @CustomerUpdateID

update CustTreeNodeAccountAssoc set YTD = @YTDSales, LYTD= @LYTDSales,Balance = @ARbal where CustTreeNodeID = @CustTreeNodeID


end
close mycursor
deallocate mycursor
AnswerRe: Sql cursor problem... Pin
A Wong12-Jun-08 4:47
A Wong12-Jun-08 4:47 
GeneralRe: Sql cursor problem... Pin
tthellebuyck12-Jun-08 5:08
tthellebuyck12-Jun-08 5:08 
AnswerRe: Sql cursor problem... Pin
Mark J. Miller12-Jun-08 7:46
Mark J. Miller12-Jun-08 7:46 
Questiondata connection and path to be written once Pin
Member 429901311-Jun-08 23:44
Member 429901311-Jun-08 23:44 
AnswerRe: data connection and path to be written once Pin
Ashfield12-Jun-08 0:17
Ashfield12-Jun-08 0:17 
Questionselect two fields that are same from one table Pin
prithaa11-Jun-08 22:35
prithaa11-Jun-08 22:35 
AnswerRe: select two fields that are same from one table Pin
Ashfield11-Jun-08 22:54
Ashfield11-Jun-08 22:54 
GeneralRe: select two fields that are same from one table Pin
prithaa11-Jun-08 23:40
prithaa11-Jun-08 23:40 
GeneralRe: select two fields that are same from one table Pin
Ashfield12-Jun-08 0:13
Ashfield12-Jun-08 0:13 
QuestionSQL Triggers [modified] Pin
sharifworldwide11-Jun-08 20:08
sharifworldwide11-Jun-08 20:08 
AnswerRe: SQL Triggers Pin
Ashfield11-Jun-08 21:22
Ashfield11-Jun-08 21:22 
GeneralRe: SQL Triggers Pin
sharifworldwide12-Jun-08 0:36
sharifworldwide12-Jun-08 0:36 
GeneralRe: SQL Triggers Pin
Ashfield12-Jun-08 1:20
Ashfield12-Jun-08 1:20 
QuestionHow can get Index of Current Save Record in Access Database? Pin
Le@rner11-Jun-08 19:22
Le@rner11-Jun-08 19:22 
AnswerCP IGNORE Pin
leckey12-Jun-08 17:43
leckey12-Jun-08 17:43 
QuestionGet row count and data set from sproc Pin
RCoate11-Jun-08 17:49
RCoate11-Jun-08 17:49 
AnswerRe: Get row count and data set from sproc Pin
Ashfield11-Jun-08 21:26
Ashfield11-Jun-08 21:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.