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 |
Rodgerga
Starting Member
3 Posts |
Posted - 2009-04-09 : 22:49:58
|
Hi, I have following requirement. I have to transfer data from Source DB X tables 1,2,3,4,5 to destination DB Y A,B,C,D,E for SIX tables. Case1:My First step is I have to check a column in destination table D.d whether it is null or not. If it's null (which is always a possibale case for the first run) we have to insert a value into it. And start our insertion process.Case 2: If column D.d is not null(Which is always a possible case when we run the code second time) , we have to check whether Min(2.a)>D.d( meaning if a value exhist in D.d we have to do a compersion before inserting records. If this conditions satisfies then we have to insert records fron source to destination else process stops.Following is my Code :DECLARE @testLog smallintSELECT DISTINCT @RunLog=MAX(log value ) FROM Destination table IF @testLog IS NULL -- Inserting value in to test log BEGIN INSERT INTO Table A (column 1,Column2) SELECT TOP 1 column1,MIN(column2) FROM table from source WHERE --- GROUP BY column2 END? Comparision (has to occurs only when testlog is not null)ELSE IF (SELECT MIN(column2) FROM 3) >(Table A.column2)? Insering BEGIN --first part INSERT INTO B SELECT * FROM 2 -- Part two INSERT INTO C SELECT * FROM 3ENDMy requirement is:If test log in Null, I have to insert a value to it and then start my insertion process with out any comparison.If test log is not null, I have to do a comparison between a tables. Column in source and destination. If the condition satisfies Insertion process has to run else process has to stop with out any insertion.Problem:But in my code, the process is going to Comparison step even the test log value is null.Any help on this is really appreciated. |
|
|
|
|
|
|