Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ankur_gurha
Starting Member
20 Posts |
Posted - 2007-10-02 : 10:28:03
|
| Hi,I am looking for a good and efficient query. I have 2 tables SingleCompanyQuote[dbo].[SingleCompanyQuote] ([SCQWorkflowID] ,[ComparisonQuoteID] ,[ProductVersionID] ,[RequestTypeID] ,[QuoteStatusID] ,[QuoteAndPrintStatusID] ,[NewBusiness] ,[ModifiedDate] ,[WorkflowStartTime] ,[ProviderRequestTime] ,[ProviderResponseTime] ,[DeleteStatus] ,[CompletedTimestamp])And[dbo].[ReAPDocument] ([DocumentGUID] ,[ReferenceID] ,[SingleCompanyQuoteID] ,[RemotePublishingAlertLogID] ,[DocumentTypeID] ,[DocumentStatusID] ,[IllustrationURL] ,[TransmissionDate] ,[ExpiryDate] ,[ReAPDocument] ,[DocumentDescription] ,[CreatingApp] ,[RetryNumber] ,[TransactionSize])My stored procedure should be taking in 4 parameters @SCQWorkflowId uniqueidentifier , @QuoteAndPrintStatus int , @IllustrationStatus int , @URL varchar(max)@Url is a comma separted string and i need to perform a similar operation UPDATE dbo.SingleCompanyQuote SET QuoteAndPrintStatusID = @QuoteAndPrintStatus WHERE SCQWorkflowID = @SCQWorkflowId IF EXISTS( SELECT * FROM dbo.ReAPDocument INNER JOIN SingleCompanyQuote ON ReAPDocument.SCQWorkflowId = SingleCompanyQuote.SCQWorkflowId WHERE SingleCompanyQuote.SCQWorkflowId = @SCQWorkflowId AND IllustrationURL = @URL ) BEGIN UPDATE dbo.ReAPDocument SET DocumentStatusID = @IllustrationStatus FROM ReAPDocument INNER JOIN SingleCompanyQuote ON ReAPDocument.SCQWorkflowId = SingleCompanyQuote.SCQWorkflowId WHERE SingleCompanyQuote.SCQWorkflowId = @SCQWorkflowId AND IllustrationURL = @URL END ELSE BEGIN INSERT INTO dbo.ReAPDocument ( SCQWorkflowID, IllustrationURL, DocumentStatusID ) VALUES ( @QuoteAndPrintStatusID, @URL, @IllustrationStatus ) ENDfor all the values in the comma seprated string .. I have a comma separated split function , but still i need to do this whole operation in some kind of cursor operation or something .. please help..as how can i update the ReAPDocument table with the appropriate value in a cursor or something.. Thanks in advanceAnkur |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-10-02 : 15:20:19
|
This is untested and there is probalby a syntax error on the INSERT, but I think it might get you in the right direction:@SCQWorkflowId uniqueidentifier , @QuoteAndPrintStatus int , @IllustrationStatus int , @URL varchar(max) -- @Url is -- a comma separted string -- and i need to perform a similar operation DECLARE @UrlTable TABLE (Url VARCHAR(MAX)) -- Adjust MAX to a number if appropriateINSERT @UrlTableSELECT ValFROM dbo.fnSplit(@URL) -- What ever split function you haveUPDATE dbo.SingleCompanyQuote SET QuoteAndPrintStatusID = @QuoteAndPrintStatus WHERE SCQWorkflowID = @SCQWorkflowId -- Upadte existing recordsUPDATE dbo.ReAPDocument SET DocumentStatusID = @IllustrationStatus FROM ReAPDocument INNER JOIN SingleCompanyQuote ON ReAPDocument.SCQWorkflowId = SingleCompanyQuote.SCQWorkflowId INNER JOIN @UrlTable AS Temp ON ReAPDocument.IllustrationURL = Temp.UrlWHERE SingleCompanyQuote.SCQWorkflowId = @SCQWorkflowId -- Add new recordsINSERT INTO dbo.ReAPDocument ( SCQWorkflowID, IllustrationURL, DocumentStatusID ) SELECT @QuoteAndPrintStatusID, Temp.Url, @IllustrationStatus FROM ReAPDocument INNER JOIN SingleCompanyQuote ON ReAPDocument.SCQWorkflowId = SingleCompanyQuote.SCQWorkflowId AND SingleCompanyQuote.SCQWorkflowId = @SCQWorkflowId LEFT OUTER JOIN @UrlTable AS Temp ON ReAPDocument.IllustrationURL = Temp.UrlWHERE SingleCompanyQuote.SCQWorkflowId IS NULL |
 |
|
|
|
|
|
|
|