September 20, 2013 at 12:00 pm
OK. I've referenced a couple books and searched this forum. Syntactically speaking, I see nothing wrong here. SSMS is refusing to accept this. Says have a syntax error at the RED text. See anything I'm not?
-- If STREET ADDRESSES are filled in DealershipOwners NO Mailing Addresses are filled then by default, it is the Mailing Address.
IF (@strStreetAddress1 <> '' ) AND ((@strMailingStreetAddress1 = '') OR (@strMailingStreetAddress1 Is Null))
....do stuff
ELSE
-- ONLY Street Address starts with "P". Most likely a PO BOX which should be MAILING.
IF (@strStreetAddress1 LIKE 'P%') AND (@strMailingStreetAddress1 <> 'P%')
....do stuff...
ELSE IF (@strStreetAddress1 LIKE 'P%') AND (@strMailingStreetAddress1 LIKE 'P%')
....do other stuff...
ELSE
....stuff to do when second set of other IFs prove false...
September 20, 2013 at 12:08 pm
RedBirdOBX (9/20/2013)
OK. I've referenced a couple books and searched this forum. Syntactically speaking, I see nothing wrong here. SSMS is refusing to accept this. Says have a syntax error at the RED text. See anything I'm not?-- If STREET ADDRESSES are filled in DealershipOwners NO Mailing Addresses are filled then by default, it is the Mailing Address.
IF (@strStreetAddress1 <> '' ) AND ((@strMailingStreetAddress1 = '') OR (@strMailingStreetAddress1 Is Null))
....do stuff
ELSE
-- ONLY Street Address starts with "P". Most likely a PO BOX which should be MAILING.
IF (@strStreetAddress1 LIKE 'P%') AND (@strMailingStreetAddress1 <> 'P%')
....do stuff...
ELSE IF (@strStreetAddress1 LIKE 'P%') AND (@strMailingStreetAddress1 LIKE 'P%')
....do other stuff...
ELSE
....stuff to do when second set of other IFs prove false...
Why not post ALL of the code so we don't have to guess what you are doing? My guess is you have more than 1 line inside the "do stuff" blocks. Assuming that is the case you need begin/end around them.
IF (@strStreetAddress1 <> '' ) AND ((@strMailingStreetAddress1 = '') OR (@strMailingStreetAddress1 Is Null))
BEGIN
....do stuff
END
ELSE
-- ONLY Street Address starts with "P". Most likely a PO BOX which should be MAILING.
IF (@strStreetAddress1 LIKE 'P%') AND (@strMailingStreetAddress1 <> 'P%')
BEGIN
....do stuff...
END
ELSE IF (@strStreetAddress1 LIKE 'P%') AND (@strMailingStreetAddress1 LIKE 'P%')
BEGIN
....do other stuff...
END
ELSE
BEGIN
....stuff to do when second set of other IFs prove false...
END
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 20, 2013 at 12:58 pm
Thanks Sean. I've tried all that. Been trying to work this out for the past couple of hours and just can't come up with something SSMS will accept. Tried CASE too. No luck. In addition, I tried removing the troublesome section into a new separate query/SP and still...no luck.
I didn't post the cost b/c I don't want to anyone to be distracted by the crazy-*** logic as I think my issue is simply syntax. I'll post the code but please try to look past the wacky things going on.
The troublesome code can be seen here:
http://www.mvdb.virginia.gov/Trial-SP.txt
OR
http://www.mvdb.virginia.gov/Trial-SP.sql
Steps 1 & 2 work fine. It all comes apart in "Step 3". In short, the source table is a "Dealership Owner" (auto) table and ot has a bunch of "Street" Address fields and then "Mailing" address fields. Sometimes the data is crossed and put in the opposite fields so I need to test for it in some kind of way.
Ultimately, the Dealership Owners are inserted into a Persons table and the addresses (here's where it breaks down) are inserted into a universal "Address" table.
Don't worry about the crazy logic. If you could tell me what I'm doing wrong in Step 3, I'd be grateful!!
September 20, 2013 at 1:05 pm
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- ==========================================================================================
-- This Stored Procedure is designed to insert Owner data, known as "Dealership Owner"
-- in OnBoard into the Persons and Owners tables.
-- ==========================================================================================
ALTER PROCEDURE [dbo].[sp_InsertOwnersFromOnboard]
AS
BEGIN
--=====================================================================================================================
--1) INSERT INTO PERSONS Table and save old OnBoard DealershipOwnerlD (PK). Creates generic Person record.
--If SSN from Onboard.DealershipOwnersID contains a "T" Number (now formatted VA Drivers License Number),
--it is inserted into the [TNumber] field. Otherwise, insert Null.
--=====================================================================================================================
INSERT INTO Persons([PersonTypeID],[TNumber],[DOB], [FirstName],[MiddleName],[LastName],[Suffix],[CreatedOn],[LastUpdated],
[LastUpdatedBy],[Notes],[Active],[OnboardDealershipOwnerID])
(SELECT DISTINCT 1,
(CASE WHEN [SSN] LIKE '[A-Z]%'
THEN [SSN]
ELSE Null
END),
Null, [FirstName],[MiddleName],[LastName],[Suffix],GetDate(),Null,Null,Null,
1, DealershipOwnersID FROM ONBOARD.dbo.DealershipOwners WHERE DealershipOwnersID BETWEEN 1 AND 2000)
--=====================================================================================================================
--2) INSERT INTO SSNS which comes from old DealershipOwners table and match it to new PersonID
--=====================================================================================================================
INSERT INTO SSNS([PersonID],[SSN],[Active])
(SELECT Persons.PersonID,
(CASE WHEN ONBOARD.dbo.DealershipOwners.SSN = ''
THEN '0'
ELSE ONBOARD.dbo.DealershipOwners.SSN
END), 1
FROM Persons INNER JOIN ONBOARD.dbo.DealershipOwners ON Persons.OnboardDealershipOwnerID = ONBOARD.dbo.DealershipOwners.DealershipOwnersID)
--=====================================================================================================================
--3) INSERT INTO PERSONSADDRESS Table
--Since each record will need to be tested, a Cursor method will be used.
--=====================================================================================================================
DECLARE @intDealershipOwnersID int,
@strStreetAddress1 varchar(50),
@strStreetAddress2 varchar(50),
@strCity varchar(50),
@strState char(2),
@strPostalCode varchar(5),
@strZipZIP4 varchar(4),
@strMailingStreetAddress1 varchar(50),
@strMailingStreetAddress2 varchar(50),
@strMailingCity varchar(50),
@strMailingState char(2),
@strMailingPostalCode varchar(5),
@strMailingZIP4 varchar(4);
DECLARE OwnerCursor CURSOR FOR SELECT [DealershipOwnersID], [StreetAddress1], [StreetAddress2], [City], [State],
[PostalCode], [ZIP4], [MailingStreetAddress1], [MailingStreetAddress2], [MailingCity], [MailingState],
[MailingPostalCode], [MailingZIP4] FROM [ONBOARD].[dbo].[DealershipOwners]
OPEN OwnerCursor;
-- Perform the first fetch. Automatically assigns returned values from row to parameters.
FETCH NEXT FROM OwnerCursor INTO
@intDealershipOwnersID, @strStreetAddress1, @strStreetAddress2, @strCity, @strState, @strPostalCode, @strZipZIP4,
@strMailingStreetAddress1, @strMailingStreetAddress2, @strMailingCity, @strMailingState, @strMailingPostalCode, @strMailingZIP4
-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
-- If STREET ADDRESSES are filled in DealershipOwners NO Mailing Addresses are filled then by default, it is the Mailing Address.
IF (@strStreetAddress1 <> '' ) AND ((@strMailingStreetAddress1 = '') OR (@strMailingStreetAddress1 Is Null))
-- "2" is Mailing Address Type. "1" is Phyiscal.
INSERT INTO PersonAddresses([PersonID],[AddressTypeID],[Address1],[Address2],[Address3],[City],[State],[ZipCode],
[Notes],[CreatedOn],[CreatedBy],[LastUpdated],[LastUpdatedBy],[Active])
(SELECT Persons.PersonID, 2, DealershipOwners.StreetAddress1, DealershipOwners.StreetAddress2, Null,
DealershipOwners.City, DealershipOwners.State, DealershipOwners.PostalCode, DealershipOwners.Notes,
GetDate(),0,Null,1,1
FROM Persons INNER JOIN ONBOARD.dbo.DealershipOwners ON Persons.OnboardDealershipOwnerID = ONBOARD.dbo.DealershipOwners.DealershipOwnersID)
-- Both sets of fields have data but can are sometimes are mislabeled in Onboard. Sometimes Phyiscal mailing information
-- is stored in Mailing, and Mailing is stored in Street. This does a 99% effective job of putting the data in the
-- correct fields.
ELSE
-- ONLY Street Address starts with "P". Most likely a PO BOX which should be MAILING.
IF (@strStreetAddress1 LIKE 'P%') AND (@strMailingStreetAddress1 <> 'P%')
-- "2" is Mailing Address Type. "1" is Physical.
-- INSERT OnBoard "Street" fields as Mailing Address Type since they start with "P".
INSERT INTO PersonAddresses([PersonID],[AddressTypeID],[Address1],[Address2],[Address3],[City],[State],[ZipCode],
[Notes],[CreatedOn],[CreatedBy],[LastUpdated],[LastUpdatedBy],[Active])
(SELECT Persons.PersonID, 2, DealershipOwners.StreetAddress1, DealershipOwners.StreetAddress2, Null,
DealershipOwners.City, DealershipOwners.State, DealershipOwners.PostalCode, DealershipOwners.Notes,
GetDate(),0,Null,1,1
FROM Persons INNER JOIN ONBOARD.dbo.DealershipOwners ON Persons.OnboardDealershipOwnerID = ONBOARD.dbo.DealershipOwners.DealershipOwnersID)
-- INSERT OnBoard "Mailing" fields as Phyiscal Address Type.
INSERT INTO PersonAddresses([PersonID],[AddressTypeID],[Address1],[Address2],[Address3],[City],[State],[ZipCode],
[Notes],[CreatedOn],[CreatedBy],[LastUpdated],[LastUpdatedBy],[Active])
(SELECT Persons.PersonID, 1, DealershipOwners.MailingStreetAddress1, DealershipOwners.MailingStreetAddress2, Null,
DealershipOwners.MailingCity, DealershipOwners.MailingState, DealershipOwners.PostalCode + DealershipOwners.ZIP4,
DealershipOwners.Notes, GetDate(),0,Null,1,1
FROM Persons INNER JOIN ONBOARD.dbo.DealershipOwners ON Persons.OnboardDealershipOwnerID = ONBOARD.dbo.DealershipOwners.DealershipOwnersID)
ELSE IF (@strStreetAddress1 LIKE 'P%') AND (@strMailingStreetAddress1 LIKE 'P%')
--Well this sucks. BOTH address sets start with P which is most likely a PO Box address. Oh well,
-- INSERT OnBoard "Street" fields as PHYSICAL Address Type.....
INSERT INTO PersonAddresses([PersonID],[AddressTypeID],[Address1],[Address2],[Address3],[City],[State],[ZipCode],
[Notes],[CreatedOn],[CreatedBy],[LastUpdated],[LastUpdatedBy],[Active])
(SELECT Persons.PersonID, 1, DealershipOwners.StreetAddress1, DealershipOwners.StreetAddress2, Null,
DealershipOwners.City, DealershipOwners.State, DealershipOwners.PostalCode, DealershipOwners.Notes,
GetDate(),0,Null,1,1
FROM Persons INNER JOIN ONBOARD.dbo.DealershipOwners ON Persons.OnboardDealershipOwnerID = ONBOARD.dbo.DealershipOwners.DealershipOwnersID)
-- INSERT OnBoard "Mailing" fields as Mailing Address Type.
INSERT INTO PersonAddresses([PersonID],[AddressTypeID],[Address1],[Address2],[Address3],[City],[State],[ZipCode],
[Notes],[CreatedOn],[CreatedBy],[LastUpdated],[LastUpdatedBy],[Active])
(SELECT Persons.PersonID, 2, DealershipOwners.MailingStreetAddress1, DealershipOwners.MailingStreetAddress2, Null,
DealershipOwners.MailingCity, DealershipOwners.MailingState, DealershipOwners.PostalCode + DealershipOwners.ZIP4,
DealershipOwners.Notes, GetDate(),0,Null,1,1
FROM Persons INNER JOIN ONBOARD.dbo.DealershipOwners ON Persons.OnboardDealershipOwnerID = ONBOARD.dbo.DealershipOwners.DealershipOwnersID)
ELSE
--At this point, it is assumed that data is stored in both sets of address fields in OnBoard AND the
-- Street fields do NOT start with P but the Mailings may.
-- INSERT OnBoard "Street" fields as PHYSICAL Address Type.....
INSERT INTO PersonAddresses([PersonID],[AddressTypeID],[Address1],[Address2],[Address3],[City],[State],[ZipCode],
[Notes],[CreatedOn],[CreatedBy],[LastUpdated],[LastUpdatedBy],[Active])
(SELECT Persons.PersonID, 1, DealershipOwners.StreetAddress1, DealershipOwners.StreetAddress2, Null,
DealershipOwners.City, DealershipOwners.State, DealershipOwners.PostalCode, DealershipOwners.Notes,
GetDate(),0,Null,1,1
FROM Persons INNER JOIN ONBOARD.dbo.DealershipOwners ON Persons.OnboardDealershipOwnerID = ONBOARD.dbo.DealershipOwners.DealershipOwnersID)
-- INSERT OnBoard "Mailing" fields as Mailing Address Type.
INSERT INTO PersonAddresses([PersonID],[AddressTypeID],[Address1],[Address2],[Address3],[City],[State],[ZipCode],
[Notes],[CreatedOn],[CreatedBy],[LastUpdated],[LastUpdatedBy],[Active])
(SELECT Persons.PersonID, 2, DealershipOwners.MailingStreetAddress1, DealershipOwners.MailingStreetAddress2, Null,
DealershipOwners.MailingCity, DealershipOwners.MailingState, DealershipOwners.PostalCode + DealershipOwners.ZIP4,
DealershipOwners.Notes, GetDate(),0,Null,1,1
FROM Persons INNER JOIN ONBOARD.dbo.DealershipOwners ON Persons.OnboardDealershipOwnerID = ONBOARD.dbo.DealershipOwners.DealershipOwnersID)
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM OwnerCursor INTO
@intDealershipOwnersID, @strStreetAddress1, @strStreetAddress2, @strCity, @strState, @strPostalCode, @strZipZIP4,
@strMailingStreetAddress1, @strMailingStreetAddress2, @strMailingCity, @strMailingState, @strMailingPostalCode, @strMailingZIP4
CLOSE CustomerCursor;
DEALLOCATE CustomerCursor;
END
September 20, 2013 at 1:15 pm
Just as I said previously. You have multiple lines inside your conditions. If you do that you MUST include begin/end.
Think about C#/Java or whatever with if conditions.
if(SomeCondition)
DoInsert();
DoInsert();
else
DoInsert();
DoInsert();
That code will obviously NOT work because the code blocks are undefined. There is an ELSE with no IF. You have done the same thing in your code.
Here it is with BEGIN/END for your conditions.
WHILE @@FETCH_STATUS = 0
-- If STREET ADDRESSES are filled in DealershipOwners NO Mailing Addresses are filled then by default, it is the Mailing Address.
IF (@strStreetAddress1 <> '' ) AND ((@strMailingStreetAddress1 = '') OR (@strMailingStreetAddress1 Is Null))
-- "2" is Mailing Address Type. "1" is Phyiscal.
INSERT INTO PersonAddresses([PersonID],[AddressTypeID],[Address1],[Address2],[Address3],[City],[State],[ZipCode],
[Notes],[CreatedOn],[CreatedBy],[LastUpdated],[LastUpdatedBy],[Active])
(SELECT Persons.PersonID, 2, DealershipOwners.StreetAddress1, DealershipOwners.StreetAddress2, Null,
DealershipOwners.City, DealershipOwners.State, DealershipOwners.PostalCode, DealershipOwners.Notes,
GetDate(),0,Null,1,1
FROM Persons INNER JOIN ONBOARD.dbo.DealershipOwners ON Persons.OnboardDealershipOwnerID = ONBOARD.dbo.DealershipOwners.DealershipOwnersID)
-- Both sets of fields have data but can are sometimes are mislabeled in Onboard. Sometimes Phyiscal mailing information
-- is stored in Mailing, and Mailing is stored in Street. This does a 99% effective job of putting the data in the
-- correct fields.
ELSE
-- ONLY Street Address starts with "P". Most likely a PO BOX which should be MAILING.
IF (@strStreetAddress1 LIKE 'P%') AND (@strMailingStreetAddress1 <> 'P%')
BEGIN
-- "2" is Mailing Address Type. "1" is Physical.
-- INSERT OnBoard "Street" fields as Mailing Address Type since they start with "P".
INSERT INTO PersonAddresses([PersonID],[AddressTypeID],[Address1],[Address2],[Address3],[City],[State],[ZipCode],
[Notes],[CreatedOn],[CreatedBy],[LastUpdated],[LastUpdatedBy],[Active])
(SELECT Persons.PersonID, 2, DealershipOwners.StreetAddress1, DealershipOwners.StreetAddress2, Null,
DealershipOwners.City, DealershipOwners.State, DealershipOwners.PostalCode, DealershipOwners.Notes,
GetDate(),0,Null,1,1
FROM Persons INNER JOIN ONBOARD.dbo.DealershipOwners ON Persons.OnboardDealershipOwnerID = ONBOARD.dbo.DealershipOwners.DealershipOwnersID)
-- INSERT OnBoard "Mailing" fields as Phyiscal Address Type.
INSERT INTO PersonAddresses([PersonID],[AddressTypeID],[Address1],[Address2],[Address3],[City],[State],[ZipCode],
[Notes],[CreatedOn],[CreatedBy],[LastUpdated],[LastUpdatedBy],[Active])
(SELECT Persons.PersonID, 1, DealershipOwners.MailingStreetAddress1, DealershipOwners.MailingStreetAddress2, Null,
DealershipOwners.MailingCity, DealershipOwners.MailingState, DealershipOwners.PostalCode + DealershipOwners.ZIP4,
DealershipOwners.Notes, GetDate(),0,Null,1,1
FROM Persons INNER JOIN ONBOARD.dbo.DealershipOwners ON Persons.OnboardDealershipOwnerID = ONBOARD.dbo.DealershipOwners.DealershipOwnersID)
END
ELSE IF (@strStreetAddress1 LIKE 'P%') AND (@strMailingStreetAddress1 LIKE 'P%')
BEGIN
--Well this sucks. BOTH address sets start with P which is most likely a PO Box address. Oh well,
-- INSERT OnBoard "Street" fields as PHYSICAL Address Type.....
INSERT INTO PersonAddresses([PersonID],[AddressTypeID],[Address1],[Address2],[Address3],[City],[State],[ZipCode],
[Notes],[CreatedOn],[CreatedBy],[LastUpdated],[LastUpdatedBy],[Active])
(SELECT Persons.PersonID, 1, DealershipOwners.StreetAddress1, DealershipOwners.StreetAddress2, Null,
DealershipOwners.City, DealershipOwners.State, DealershipOwners.PostalCode, DealershipOwners.Notes,
GetDate(),0,Null,1,1
FROM Persons INNER JOIN ONBOARD.dbo.DealershipOwners ON Persons.OnboardDealershipOwnerID = ONBOARD.dbo.DealershipOwners.DealershipOwnersID)
-- INSERT OnBoard "Mailing" fields as Mailing Address Type.
INSERT INTO PersonAddresses([PersonID],[AddressTypeID],[Address1],[Address2],[Address3],[City],[State],[ZipCode],
[Notes],[CreatedOn],[CreatedBy],[LastUpdated],[LastUpdatedBy],[Active])
(SELECT Persons.PersonID, 2, DealershipOwners.MailingStreetAddress1, DealershipOwners.MailingStreetAddress2, Null,
DealershipOwners.MailingCity, DealershipOwners.MailingState, DealershipOwners.PostalCode + DealershipOwners.ZIP4,
DealershipOwners.Notes, GetDate(),0,Null,1,1
FROM Persons INNER JOIN ONBOARD.dbo.DealershipOwners ON Persons.OnboardDealershipOwnerID = ONBOARD.dbo.DealershipOwners.DealershipOwnersID)
END
ELSE
BEGIN
--At this point, it is assumed that data is stored in both sets of address fields in OnBoard AND the
-- Street fields do NOT start with P but the Mailings may.
-- INSERT OnBoard "Street" fields as PHYSICAL Address Type.....
INSERT INTO PersonAddresses([PersonID],[AddressTypeID],[Address1],[Address2],[Address3],[City],[State],[ZipCode],
[Notes],[CreatedOn],[CreatedBy],[LastUpdated],[LastUpdatedBy],[Active])
(SELECT Persons.PersonID, 1, DealershipOwners.StreetAddress1, DealershipOwners.StreetAddress2, Null,
DealershipOwners.City, DealershipOwners.State, DealershipOwners.PostalCode, DealershipOwners.Notes,
GetDate(),0,Null,1,1
FROM Persons INNER JOIN ONBOARD.dbo.DealershipOwners ON Persons.OnboardDealershipOwnerID = ONBOARD.dbo.DealershipOwners.DealershipOwnersID)
-- INSERT OnBoard "Mailing" fields as Mailing Address Type.
INSERT INTO PersonAddresses([PersonID],[AddressTypeID],[Address1],[Address2],[Address3],[City],[State],[ZipCode],
[Notes],[CreatedOn],[CreatedBy],[LastUpdated],[LastUpdatedBy],[Active])
(SELECT Persons.PersonID, 2, DealershipOwners.MailingStreetAddress1, DealershipOwners.MailingStreetAddress2, Null,
DealershipOwners.MailingCity, DealershipOwners.MailingState, DealershipOwners.PostalCode + DealershipOwners.ZIP4,
DealershipOwners.Notes, GetDate(),0,Null,1,1
FROM Persons INNER JOIN ONBOARD.dbo.DealershipOwners ON Persons.OnboardDealershipOwnerID = ONBOARD.dbo.DealershipOwners.DealershipOwnersID)
END
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM OwnerCursor INTO
@intDealershipOwnersID, @strStreetAddress1, @strStreetAddress2, @strCity, @strState, @strPostalCode, @strZipZIP4,
@strMailingStreetAddress1, @strMailingStreetAddress2, @strMailingCity, @strMailingState, @strMailingPostalCode, @strMailingZIP4
Now...you really don't need to use a **cough**cursor**cough** here. It will take more effort than I have time for today to remove that cursor but it can be removed.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 20, 2013 at 1:25 pm
I'm mostly a VB.NET guy so those same rules don't apply. I am slowly teaching myself C# though so I'm sure I would have come across that in C# eventually. I suppose VB is a little more forgiving. In any event, I'm trilled that it works so THANKS. I'll study what you said on Monday morning with a fresher brain.
Thanks again!
September 20, 2013 at 1:33 pm
RedBirdOBX (9/20/2013)
I'm mostly a VB.NET guy so those same rules don't apply. I am slowly teaching myself C# though so I'm sure I would have come across that in C# eventually. I suppose VB is a little more forgiving. In any event, I'm trilled that it works so THANKS. I'll study what you said on Monday morning with a fresher brain.Thanks again!
No actually VB.NET is MORE ridgid. The block terminators are required in VB.NET.
IF SomeCondition THEN
DoInsert
DoInsert
END IF
The code you posted has no THEN or END IF. What that means is that ONLY the next line is part of the block.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 20, 2013 at 1:41 pm
Makes sense now. I kept typing THEN just by nature...only to have to go back and delete it.
Thanks!
September 20, 2013 at 1:50 pm
You're welcome. Glad it makes sense now. At least you will be able to sleep this weekend. 😀
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply