| Author |
Topic |
|
Schnoz
Starting Member
4 Posts |
Posted - 2009-08-13 : 14:39:13
|
| I have a stored procedure that is inserting a bunch of rows from a table into another table in another database. First of all, I am using a fetch statement to run through each row. The only problem is, the fetch is only pulling rows that don't have a null in them (anywhere in them). Some rows have a null in the street column and some in the zip code column. The fetch won't pull any of those rows. It will only pull the rows that have complete data. Is there any way to get the fetch to pull the rows that have the null value as well as all other rows? I want to input that column that has null as a null in the new table on the other database. |
|
|
Schnoz
Starting Member
4 Posts |
Posted - 2009-08-13 : 14:40:34
|
| BTW, here is the stored procedure if anybody needs to look at the code:Declare @ID nvarchar(255)Declare @LastName nvarchar(255)Declare @FirstName nvarchar(255)Declare @Street nvarchar(255)Declare @City nvarchar(255)Declare @Zip nvarchar(255)Declare @State nvarchar(255)Declare @Phone nvarchar(255)Declare @EmailAddress nvarchar(255)BEGIN TRANSACTIONDECLARE c1 CURSOR FORSELECT ID, LastName, FirstName, Street, City, Zip, State, Phone, EmailAddressFROM Caspa_eSubmittedOPEN c1FETCH NEXT FROM c1INTO @ID, @LastName, @FirstName, @Street, @City, @Zip, @State, @Phone, @EmailAddress WHILE @@FETCH_STATUS = 0 BEGIN Declare @State_Num varchar(100) Set @State_Num = (SELECT State_Num FROM SRPDB.dbo.DomState WHERE StateAbbrev = @State) DECLARE @SQL varchar(8000) SET @SQL=' INSERT INTO SRPDB.dbo.tbImportStudent (LastName,FirstName, Street1, City, ZipCode,SATE_PKId, Phone1Number, EmailAddress, Priority, InsWho, InsDate, OVER_PKID) VALUES (''' + @LastName + ''',''' + @FirstName + ''',''' + @Street + ''',''' + @City + ''',''' + @Zip + ''',' + @State_Num + ', ''' + @Phone + ''',''' + @EmailAddress + ''', 3,''Online Application'',getdate(),1)' PRINT @SQL EXEC(@SQL) FETCH NEXT FROM c1 INTO @ID, @LastName, @FirstName, @Street, @City, @Zip, @State, @Phone, @EmailAddress ENDCLOSE c1DEALLOCATE c1COMMIT TRANSACTION |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-08-13 : 15:15:31
|
Maybe I'm missing something...but won't this do??INSERT INTO SRPDB.dbo.tbImportStudent (LastName, FirstName, Street1, City, ZipCode, SATE_PKId, Phone1Number, EmailAddress, Priority, InsWho, InsDate, OVER_PKID) SELECT a.ID, a.LastName, a.FirstName, a.Street, a.City, a.Zip, b.State_Num, a.Phone, a.EmailAddress, 3, 'Online Application', getdate(), 1 FROM Caspa_eSubmitted a INNER JOIN SRPDB.dbo.DomState b ON b.StateAbbrev = a.State |
 |
|
|
|
|
|