Showing posts with label suppose. Show all posts
Showing posts with label suppose. Show all posts

Wednesday, March 7, 2012

my store procedure that call back itself doesn't seems to work.

I have written a store procedure that will delete the record and any children record of it. That store procedure is suppose to call back itself to for every children record, but it only seems to delete the first record (the parent record). Below is my store procedure, pls help.

CREATE PROCEDURE [deleteCMSPage]
(@.PROJ_CMS_PAGE_ID [int])

AS

/* do not delete page id 1 */
if @.PROJ_CMS_PAGE_ID <> 1
begin
-- For storing the list of child activities.
DECLARE @.page_list_cursor CURSOR
DECLARE @.CHILD_ID INTEGER
/* get the children of this page, for every child, call deleteCMSPage */
SET @.page_list_cursor = CURSOR FOR
SELECT PROJ_CMS_PAGE_ID
FROM TBL_PROJ_CMS_PAGE
WHERE PARENT_ID = @.PROJ_CMS_PAGE_ID
ORDER BY PAGE_ORDER

-- Populate the cursor.
OPEN @.page_list_cursor

WHILE (@.@.FETCH_STATUS = 0)
BEGIN
-- Fetch the details for next activity.
FETCH NEXT FROM @.page_list_cursor
INTO @.CHILD_ID
-- Calls itself, i.e
-- as parent to get all child nodes associated with it.
EXECUTE deleteCMSPage @.CHILD_ID
END
-- Close the cursor.
CLOSE @.page_list_cursor
-- Deallocate the cursor.
DEALLOCATE @.page_list_cursor
DELETE TBL_PROJ_CMS_PAGE
WHERE PROJ_CMS_PAGE_ID = @.PROJ_CMS_PAGE_ID
end
GO

The global variable @.@.FETCH_STATUS is set only when you perform a fetch. So the WHILE loop condition is wrong. You should code it like:

while (1=1)

begin

fetch...

if @.@.fetch_status < 0 break

...

end

|||

I have change the code, and right now it only delete the first branch, eg. root, first child, child of first child ..etc, I am not sure why.

CREATE PROCEDURE [deleteCMSPage]
(@.PROJ_CMS_PAGE_ID [int])

AS

/* do not delete page id 1 */
if @.PROJ_CMS_PAGE_ID <> 1
begin
-- For storing the list of child activities.
DECLARE @.page_list_cursor CURSOR
DECLARE @.CHILD_ID INTEGER
/* get the children of this page, for every child, call deleteCMSPage */
SET @.page_list_cursor = CURSOR FOR
SELECT PROJ_CMS_PAGE_ID
FROM TBL_PROJ_CMS_PAGE
WHERE PARENT_ID = @.PROJ_CMS_PAGE_ID
ORDER BY PAGE_ORDER

-- Populate the cursor.
OPEN @.page_list_cursor

while (1=1)
BEGIN

-- Fetch the details for next activity.
FETCH NEXT FROM @.page_list_cursor
INTO @.CHILD_ID
-- Calls itself, i.e
-- as parent to get all child nodes associated with it.
EXECUTE deleteCMSPage @.CHILD_ID
if @.@.fetch_status < 0 break
END
-- Close the cursor.
CLOSE @.page_list_cursor
-- Deallocate the cursor.
DEALLOCATE @.page_list_cursor
DELETE TBL_PROJ_CMS_PAGE
WHERE PROJ_CMS_PAGE_ID = @.PROJ_CMS_PAGE_ID
end
GO

|||

You have the CHECK for FETCH in the wrong place not like what I showed. Here you are checking FETCH_STATUS of some fetch operation that happened within the delete SP not the one before the call to the SP. So you should change below:

-- Fetch the details for next activity.
FETCH NEXT FROM @.page_list_cursor
INTO @.CHILD_ID

-- Calls itself, i.e
-- as parent to get all child nodes associated with it.
EXECUTE deleteCMSPage @.CHILD_ID
if @.@.fetch_status < 0 break

to:

-- Fetch the details for next activity.
FETCH NEXT FROM @.page_list_cursor
INTO @.CHILD_ID

if @.@.fetch_status < 0 break

-- Calls itself, i.e
-- as parent to get all child nodes associated with it.
EXECUTE deleteCMSPage @.CHILD_ID

|||thanks for you help, it's working now. :)

Saturday, February 25, 2012

My SP works on 2005 bit not on 2000 it doesn''t step through my code.

Hi

I have a SP that works on SQL 2000 but not on 2005

It is just suppose to step through my code and insert values into tables where it finds the "ticked" values

here is apiece of my code. I hope it Helps.

Code Snippet

INSERT INTO Members (ClientID, Name, Surname, Email, Username, Password, Active, WlcSent)

SELECT ClientID, [Name], Surname, Email, Username, Password, Active, [Welcome Sent]

FROM StageMemberUploading

WHERE ID = @.numValues

SET @.CurrentValue = (SELECT SCOPE_IDENTITY())

IF @.ClientID IS NOT NULL BEGIN

INSERT INTO MemberUsergroup (MemberID, ClientID, UsergroupID)

VALUES (@.CurrentValue, @.ClientID, @.UsergroupID)

END

IF @.DateOfBirth IS NOT NULL BEGIN

INSERT INTO _MemberProfileCharacterValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 1, @.DateOfBirth)

END

-My Code Stops here

IF @.Male = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 1)

END

IF @.Female = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 3)

END

Any help would be greatly appreciated

Kind Regards

Carel greaves

Well, without knowing where you get the values of @.clientId or what the value was, there is no telling. No where in your code does the ClientId get set.

Can you add some print statements to your code to show what the values are? Preferrably before and after the IF statements, so you can see the value, and then if it actually got inside the block.

|||What do you mean "My Code Stops Here"? Are you getting an error? Or is it just not matching any of your IF statements as you expect?

Without seeing the entire SP and sample data, there is no telling what is causing your problem.

|||

Hi sorry, here is the whole procedure. Whe iu said my code stops here, it doesn't give me an error, it means that it doesn't run through the if statements, so it inserts the member's details into my members table and then it stops. That's all, doesn't look like it even touches my IF statements, and it doesn't give me any error codes.

Sorry about before, i was more confused, so i didn't know what data to put on the forum for help.

Here is all the code for my SP.

Code Snippet

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

ALTER PROCEDURE [dbo].[csp_MemberUploader]

AS

DECLARE @.CurrentValue INT

DECLARE @.numValues INT

DECLARE @.MaxValue INT

SELECT @.numValues = COUNT(ID), @.MaxValue = MAX(ID)

FROM StageMemberUploading

WHILE @.numValues <> 0

BEGIN

DECLARE @.DateOfBirth DATETIME

DECLARE @.Male VARCHAR(50)

DECLARE @.Female VARCHAR(50)

DECLARE @.Single VARCHAR(50)

DECLARE @.Married VARCHAR(50)

DECLARE @.Divorced VARCHAR(50)

DECLARE @.Widowed VARCHAR(50)

DECLARE @.Height VARCHAR(50)

DECLARE @.Weight VARCHAR(50)

DECLARE @.Absentism VARCHAR(50)

DECLARE @.UsergroupID INT

DECLARE @.ClientID INT

SELECT @.DateOfBirth = [Date of birth],

@.Male = [Male],

@.Female = [Female],

@.Single = [Single],

@.Married = [Married],

@.Divorced = [Divorced],

@.Widowed = [Widowed],

@.Height = [Height],

@.Weight = [Weight],

@.Absentism = [Absentism],

@.UsergroupID = UsergroupID,

@.ClientID = ClientID

FROM StageMemberUploading

WHERE ID = @.numValues

INSERT INTO Members (ClientID, Name, Surname, Email, Username, Password, Active, WlcSent)

SELECT ClientID, [Name], Surname, Email, Username, Password, Active, [Welcome Sent]

FROM StageMemberUploading

WHERE ID = @.numValues

SET @.CurrentValue = (SELECT SCOPE_IDENTITY())

IF @.ClientID IS NOT NULL BEGIN

INSERT INTO MemberUsergroup (MemberID, ClientID, UsergroupID)

VALUES (@.CurrentValue, @.ClientID, @.UsergroupID)

END

IF @.DateOfBirth IS NOT NULL BEGIN

INSERT INTO _MemberProfileCharacterValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 1, @.DateOfBirth)

END

IF @.Male = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 1)

END

IF @.Female = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 3)

END

IF @.Single = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 8)

END

IF @.Married = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 7)

END

IF @.Divorced = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 9)

END

IF @.Widowed = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 10)

END

IF @.Height = '1.22' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 3, 85)

END

IF @.Weight = 'x' BEGIN

INSERT INTO _MemberProfileNumericValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 4, @.Weight)

END

IF @.Absentism = '1' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 158)

END

IF @.Absentism = '2' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 159)

END

IF @.Absentism = '3' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 160)

END

IF @.Absentism = '4' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 161)

END

SET @.numValues = @.numValues - 1

END

Kind Regards

Carel Greaves

|||

As far as i can see, your proc looks fine and there aren't any glaring errors. Which leads me to believe its the data that is causing the problems.


I'd definitely follow Louis' advice and add print statements before you go into the IF blocks so you can check the data against that of the table.

PRINT @.NumValues

PRINT @.CurrentValue

PRINT @.Absentism

....

|||My first guess is your values for @.Male, @.Female, etc are NULL.

Add some commands like this and see what you get:

IF @.Male IS NULL
PRINT '@.Male is NULL'
ELSE
PRINT '@.Male=['+@.Male+']'

My SP works on 2005 bit not on 2000 it doesn''t step through my code.

Hi

I have a SP that works on SQL 2000 but not on 2005

It is just suppose to step through my code and insert values into tables where it finds the "ticked" values

here is apiece of my code. I hope it Helps.

Code Snippet

INSERT INTO Members (ClientID, Name, Surname, Email, Username, Password, Active, WlcSent)

SELECT ClientID, [Name], Surname, Email, Username, Password, Active, [Welcome Sent]

FROM StageMemberUploading

WHERE ID = @.numValues

SET @.CurrentValue = (SELECT SCOPE_IDENTITY())

IF @.ClientID IS NOT NULL BEGIN

INSERT INTO MemberUsergroup (MemberID, ClientID, UsergroupID)

VALUES (@.CurrentValue, @.ClientID, @.UsergroupID)

END

IF @.DateOfBirth IS NOT NULL BEGIN

INSERT INTO _MemberProfileCharacterValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 1, @.DateOfBirth)

END

-My Code Stops here

IF @.Male = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 1)

END

IF @.Female = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 3)

END

Any help would be greatly appreciated

Kind Regards

Carel greaves

Well, without knowing where you get the values of @.clientId or what the value was, there is no telling. No where in your code does the ClientId get set.

Can you add some print statements to your code to show what the values are? Preferrably before and after the IF statements, so you can see the value, and then if it actually got inside the block.

|||What do you mean "My Code Stops Here"? Are you getting an error? Or is it just not matching any of your IF statements as you expect?

Without seeing the entire SP and sample data, there is no telling what is causing your problem.

|||

Hi sorry, here is the whole procedure. Whe iu said my code stops here, it doesn't give me an error, it means that it doesn't run through the if statements, so it inserts the member's details into my members table and then it stops. That's all, doesn't look like it even touches my IF statements, and it doesn't give me any error codes.

Sorry about before, i was more confused, so i didn't know what data to put on the forum for help.

Here is all the code for my SP.

Code Snippet

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

ALTER PROCEDURE [dbo].[csp_MemberUploader]

AS

DECLARE @.CurrentValue INT

DECLARE @.numValues INT

DECLARE @.MaxValue INT

SELECT @.numValues = COUNT(ID), @.MaxValue = MAX(ID)

FROM StageMemberUploading

WHILE @.numValues <> 0

BEGIN

DECLARE @.DateOfBirth DATETIME

DECLARE @.Male VARCHAR(50)

DECLARE @.Female VARCHAR(50)

DECLARE @.Single VARCHAR(50)

DECLARE @.Married VARCHAR(50)

DECLARE @.Divorced VARCHAR(50)

DECLARE @.Widowed VARCHAR(50)

DECLARE @.Height VARCHAR(50)

DECLARE @.Weight VARCHAR(50)

DECLARE @.Absentism VARCHAR(50)

DECLARE @.UsergroupID INT

DECLARE @.ClientID INT

SELECT @.DateOfBirth = [Date of birth],

@.Male = [Male],

@.Female = [Female],

@.Single = [Single],

@.Married = [Married],

@.Divorced = [Divorced],

@.Widowed = [Widowed],

@.Height = [Height],

@.Weight = [Weight],

@.Absentism = [Absentism],

@.UsergroupID = UsergroupID,

@.ClientID = ClientID

FROM StageMemberUploading

WHERE ID = @.numValues

INSERT INTO Members (ClientID, Name, Surname, Email, Username, Password, Active, WlcSent)

SELECT ClientID, [Name], Surname, Email, Username, Password, Active, [Welcome Sent]

FROM StageMemberUploading

WHERE ID = @.numValues

SET @.CurrentValue = (SELECT SCOPE_IDENTITY())

IF @.ClientID IS NOT NULL BEGIN

INSERT INTO MemberUsergroup (MemberID, ClientID, UsergroupID)

VALUES (@.CurrentValue, @.ClientID, @.UsergroupID)

END

IF @.DateOfBirth IS NOT NULL BEGIN

INSERT INTO _MemberProfileCharacterValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 1, @.DateOfBirth)

END

IF @.Male = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 1)

END

IF @.Female = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 3)

END

IF @.Single = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 8)

END

IF @.Married = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 7)

END

IF @.Divorced = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 9)

END

IF @.Widowed = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 10)

END

IF @.Height = '1.22' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 3, 85)

END

IF @.Weight = 'x' BEGIN

INSERT INTO _MemberProfileNumericValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 4, @.Weight)

END

IF @.Absentism = '1' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 158)

END

IF @.Absentism = '2' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 159)

END

IF @.Absentism = '3' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 160)

END

IF @.Absentism = '4' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 161)

END

SET @.numValues = @.numValues - 1

END

Kind Regards

Carel Greaves

|||

As far as i can see, your proc looks fine and there aren't any glaring errors. Which leads me to believe its the data that is causing the problems.


I'd definitely follow Louis' advice and add print statements before you go into the IF blocks so you can check the data against that of the table.

PRINT @.NumValues

PRINT @.CurrentValue

PRINT @.Absentism

....

|||My first guess is your values for @.Male, @.Female, etc are NULL.

Add some commands like this and see what you get:

IF @.Male IS NULL
PRINT '@.Male is NULL'
ELSE
PRINT '@.Male=['+@.Male+']'

My SP works on 2005 bit not on 2000 it doesn''t step through my code.

Hi

I have a SP that works on SQL 2000 but not on 2005

It is just suppose to step through my code and insert values into tables where it finds the "ticked" values

here is apiece of my code. I hope it Helps.

Code Snippet

INSERT INTO Members (ClientID, Name, Surname, Email, Username, Password, Active, WlcSent)

SELECT ClientID, [Name], Surname, Email, Username, Password, Active, [Welcome Sent]

FROM StageMemberUploading

WHERE ID = @.numValues

SET @.CurrentValue = (SELECT SCOPE_IDENTITY())

IF @.ClientID IS NOT NULL BEGIN

INSERT INTO MemberUsergroup (MemberID, ClientID, UsergroupID)

VALUES (@.CurrentValue, @.ClientID, @.UsergroupID)

END

IF @.DateOfBirth IS NOT NULL BEGIN

INSERT INTO _MemberProfileCharacterValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 1, @.DateOfBirth)

END

-My Code Stops here

IF @.Male = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 1)

END

IF @.Female = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 3)

END

Any help would be greatly appreciated

Kind Regards

Carel greaves

Well, without knowing where you get the values of @.clientId or what the value was, there is no telling. No where in your code does the ClientId get set.

Can you add some print statements to your code to show what the values are? Preferrably before and after the IF statements, so you can see the value, and then if it actually got inside the block.

|||What do you mean "My Code Stops Here"? Are you getting an error? Or is it just not matching any of your IF statements as you expect?

Without seeing the entire SP and sample data, there is no telling what is causing your problem.

|||

Hi sorry, here is the whole procedure. Whe iu said my code stops here, it doesn't give me an error, it means that it doesn't run through the if statements, so it inserts the member's details into my members table and then it stops. That's all, doesn't look like it even touches my IF statements, and it doesn't give me any error codes.

Sorry about before, i was more confused, so i didn't know what data to put on the forum for help.

Here is all the code for my SP.

Code Snippet

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

ALTER PROCEDURE [dbo].[csp_MemberUploader]

AS

DECLARE @.CurrentValue INT

DECLARE @.numValues INT

DECLARE @.MaxValue INT

SELECT @.numValues = COUNT(ID), @.MaxValue = MAX(ID)

FROM StageMemberUploading

WHILE @.numValues <> 0

BEGIN

DECLARE @.DateOfBirth DATETIME

DECLARE @.Male VARCHAR(50)

DECLARE @.Female VARCHAR(50)

DECLARE @.Single VARCHAR(50)

DECLARE @.Married VARCHAR(50)

DECLARE @.Divorced VARCHAR(50)

DECLARE @.Widowed VARCHAR(50)

DECLARE @.Height VARCHAR(50)

DECLARE @.Weight VARCHAR(50)

DECLARE @.Absentism VARCHAR(50)

DECLARE @.UsergroupID INT

DECLARE @.ClientID INT

SELECT @.DateOfBirth = [Date of birth],

@.Male = [Male],

@.Female = [Female],

@.Single = [Single],

@.Married = [Married],

@.Divorced = [Divorced],

@.Widowed = [Widowed],

@.Height = [Height],

@.Weight = [Weight],

@.Absentism = [Absentism],

@.UsergroupID = UsergroupID,

@.ClientID = ClientID

FROM StageMemberUploading

WHERE ID = @.numValues

INSERT INTO Members (ClientID, Name, Surname, Email, Username, Password, Active, WlcSent)

SELECT ClientID, [Name], Surname, Email, Username, Password, Active, [Welcome Sent]

FROM StageMemberUploading

WHERE ID = @.numValues

SET @.CurrentValue = (SELECT SCOPE_IDENTITY())

IF @.ClientID IS NOT NULL BEGIN

INSERT INTO MemberUsergroup (MemberID, ClientID, UsergroupID)

VALUES (@.CurrentValue, @.ClientID, @.UsergroupID)

END

IF @.DateOfBirth IS NOT NULL BEGIN

INSERT INTO _MemberProfileCharacterValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 1, @.DateOfBirth)

END

IF @.Male = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 1)

END

IF @.Female = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 3)

END

IF @.Single = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 8)

END

IF @.Married = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 7)

END

IF @.Divorced = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 9)

END

IF @.Widowed = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 10)

END

IF @.Height = '1.22' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 3, 85)

END

IF @.Weight = 'x' BEGIN

INSERT INTO _MemberProfileNumericValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 4, @.Weight)

END

IF @.Absentism = '1' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 158)

END

IF @.Absentism = '2' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 159)

END

IF @.Absentism = '3' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 160)

END

IF @.Absentism = '4' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 161)

END

SET @.numValues = @.numValues - 1

END

Kind Regards

Carel Greaves

|||

As far as i can see, your proc looks fine and there aren't any glaring errors. Which leads me to believe its the data that is causing the problems.


I'd definitely follow Louis' advice and add print statements before you go into the IF blocks so you can check the data against that of the table.

PRINT @.NumValues

PRINT @.CurrentValue

PRINT @.Absentism

....

|||My first guess is your values for @.Male, @.Female, etc are NULL.

Add some commands like this and see what you get:

IF @.Male IS NULL
PRINT '@.Male is NULL'
ELSE
PRINT '@.Male=['+@.Male+']'

My SP works on 2005 bit not on 2000 it doesn''t step through my code.

Hi

I have a SP that works on SQL 2000 but not on 2005

It is just suppose to step through my code and insert values into tables where it finds the "ticked" values

here is apiece of my code. I hope it Helps.

Code Snippet

INSERT INTO Members (ClientID, Name, Surname, Email, Username, Password, Active, WlcSent)

SELECT ClientID, [Name], Surname, Email, Username, Password, Active, [Welcome Sent]

FROM StageMemberUploading

WHERE ID = @.numValues

SET @.CurrentValue = (SELECT SCOPE_IDENTITY())

IF @.ClientID IS NOT NULL BEGIN

INSERT INTO MemberUsergroup (MemberID, ClientID, UsergroupID)

VALUES (@.CurrentValue, @.ClientID, @.UsergroupID)

END

IF @.DateOfBirth IS NOT NULL BEGIN

INSERT INTO _MemberProfileCharacterValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 1, @.DateOfBirth)

END

-My Code Stops here

IF @.Male = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 1)

END

IF @.Female = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 3)

END

Any help would be greatly appreciated

Kind Regards

Carel greaves

Well, without knowing where you get the values of @.clientId or what the value was, there is no telling. No where in your code does the ClientId get set.

Can you add some print statements to your code to show what the values are? Preferrably before and after the IF statements, so you can see the value, and then if it actually got inside the block.

|||What do you mean "My Code Stops Here"? Are you getting an error? Or is it just not matching any of your IF statements as you expect?

Without seeing the entire SP and sample data, there is no telling what is causing your problem.

|||

Hi sorry, here is the whole procedure. Whe iu said my code stops here, it doesn't give me an error, it means that it doesn't run through the if statements, so it inserts the member's details into my members table and then it stops. That's all, doesn't look like it even touches my IF statements, and it doesn't give me any error codes.

Sorry about before, i was more confused, so i didn't know what data to put on the forum for help.

Here is all the code for my SP.

Code Snippet

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

ALTER PROCEDURE [dbo].[csp_MemberUploader]

AS

DECLARE @.CurrentValue INT

DECLARE @.numValues INT

DECLARE @.MaxValue INT

SELECT @.numValues = COUNT(ID), @.MaxValue = MAX(ID)

FROM StageMemberUploading

WHILE @.numValues <> 0

BEGIN

DECLARE @.DateOfBirth DATETIME

DECLARE @.Male VARCHAR(50)

DECLARE @.Female VARCHAR(50)

DECLARE @.Single VARCHAR(50)

DECLARE @.Married VARCHAR(50)

DECLARE @.Divorced VARCHAR(50)

DECLARE @.Widowed VARCHAR(50)

DECLARE @.Height VARCHAR(50)

DECLARE @.Weight VARCHAR(50)

DECLARE @.Absentism VARCHAR(50)

DECLARE @.UsergroupID INT

DECLARE @.ClientID INT

SELECT @.DateOfBirth = [Date of birth],

@.Male = [Male],

@.Female = [Female],

@.Single = [Single],

@.Married = [Married],

@.Divorced = [Divorced],

@.Widowed = [Widowed],

@.Height = [Height],

@.Weight = [Weight],

@.Absentism = [Absentism],

@.UsergroupID = UsergroupID,

@.ClientID = ClientID

FROM StageMemberUploading

WHERE ID = @.numValues

INSERT INTO Members (ClientID, Name, Surname, Email, Username, Password, Active, WlcSent)

SELECT ClientID, [Name], Surname, Email, Username, Password, Active, [Welcome Sent]

FROM StageMemberUploading

WHERE ID = @.numValues

SET @.CurrentValue = (SELECT SCOPE_IDENTITY())

IF @.ClientID IS NOT NULL BEGIN

INSERT INTO MemberUsergroup (MemberID, ClientID, UsergroupID)

VALUES (@.CurrentValue, @.ClientID, @.UsergroupID)

END

IF @.DateOfBirth IS NOT NULL BEGIN

INSERT INTO _MemberProfileCharacterValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 1, @.DateOfBirth)

END

IF @.Male = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 1)

END

IF @.Female = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 3)

END

IF @.Single = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 8)

END

IF @.Married = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 7)

END

IF @.Divorced = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 9)

END

IF @.Widowed = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 10)

END

IF @.Height = '1.22' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 3, 85)

END

IF @.Weight = 'x' BEGIN

INSERT INTO _MemberProfileNumericValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 4, @.Weight)

END

IF @.Absentism = '1' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 158)

END

IF @.Absentism = '2' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 159)

END

IF @.Absentism = '3' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 160)

END

IF @.Absentism = '4' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 161)

END

SET @.numValues = @.numValues - 1

END

Kind Regards

Carel Greaves

|||

As far as i can see, your proc looks fine and there aren't any glaring errors. Which leads me to believe its the data that is causing the problems.


I'd definitely follow Louis' advice and add print statements before you go into the IF blocks so you can check the data against that of the table.

PRINT @.NumValues

PRINT @.CurrentValue

PRINT @.Absentism

....

|||My first guess is your values for @.Male, @.Female, etc are NULL.

Add some commands like this and see what you get:

IF @.Male IS NULL
PRINT '@.Male is NULL'
ELSE
PRINT '@.Male=['+@.Male+']'

My SP works on 2005 bit not on 2000 it doesn''t step through my code.

Hi

I have a SP that works on SQL 2000 but not on 2005

It is just suppose to step through my code and insert values into tables where it finds the "ticked" values

here is apiece of my code. I hope it Helps.

Code Snippet

INSERT INTO Members (ClientID, Name, Surname, Email, Username, Password, Active, WlcSent)

SELECT ClientID, [Name], Surname, Email, Username, Password, Active, [Welcome Sent]

FROM StageMemberUploading

WHERE ID = @.numValues

SET @.CurrentValue = (SELECT SCOPE_IDENTITY())

IF @.ClientID IS NOT NULL BEGIN

INSERT INTO MemberUsergroup (MemberID, ClientID, UsergroupID)

VALUES (@.CurrentValue, @.ClientID, @.UsergroupID)

END

IF @.DateOfBirth IS NOT NULL BEGIN

INSERT INTO _MemberProfileCharacterValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 1, @.DateOfBirth)

END

-My Code Stops here

IF @.Male = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 1)

END

IF @.Female = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 3)

END

Any help would be greatly appreciated

Kind Regards

Carel greaves

Well, without knowing where you get the values of @.clientId or what the value was, there is no telling. No where in your code does the ClientId get set.

Can you add some print statements to your code to show what the values are? Preferrably before and after the IF statements, so you can see the value, and then if it actually got inside the block.

|||What do you mean "My Code Stops Here"? Are you getting an error? Or is it just not matching any of your IF statements as you expect?

Without seeing the entire SP and sample data, there is no telling what is causing your problem.

|||

Hi sorry, here is the whole procedure. Whe iu said my code stops here, it doesn't give me an error, it means that it doesn't run through the if statements, so it inserts the member's details into my members table and then it stops. That's all, doesn't look like it even touches my IF statements, and it doesn't give me any error codes.

Sorry about before, i was more confused, so i didn't know what data to put on the forum for help.

Here is all the code for my SP.

Code Snippet

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

ALTER PROCEDURE [dbo].[csp_MemberUploader]

AS

DECLARE @.CurrentValue INT

DECLARE @.numValues INT

DECLARE @.MaxValue INT

SELECT @.numValues = COUNT(ID), @.MaxValue = MAX(ID)

FROM StageMemberUploading

WHILE @.numValues <> 0

BEGIN

DECLARE @.DateOfBirth DATETIME

DECLARE @.Male VARCHAR(50)

DECLARE @.Female VARCHAR(50)

DECLARE @.Single VARCHAR(50)

DECLARE @.Married VARCHAR(50)

DECLARE @.Divorced VARCHAR(50)

DECLARE @.Widowed VARCHAR(50)

DECLARE @.Height VARCHAR(50)

DECLARE @.Weight VARCHAR(50)

DECLARE @.Absentism VARCHAR(50)

DECLARE @.UsergroupID INT

DECLARE @.ClientID INT

SELECT @.DateOfBirth = [Date of birth],

@.Male = [Male],

@.Female = [Female],

@.Single = [Single],

@.Married = [Married],

@.Divorced = [Divorced],

@.Widowed = [Widowed],

@.Height = [Height],

@.Weight = [Weight],

@.Absentism = [Absentism],

@.UsergroupID = UsergroupID,

@.ClientID = ClientID

FROM StageMemberUploading

WHERE ID = @.numValues

INSERT INTO Members (ClientID, Name, Surname, Email, Username, Password, Active, WlcSent)

SELECT ClientID, [Name], Surname, Email, Username, Password, Active, [Welcome Sent]

FROM StageMemberUploading

WHERE ID = @.numValues

SET @.CurrentValue = (SELECT SCOPE_IDENTITY())

IF @.ClientID IS NOT NULL BEGIN

INSERT INTO MemberUsergroup (MemberID, ClientID, UsergroupID)

VALUES (@.CurrentValue, @.ClientID, @.UsergroupID)

END

IF @.DateOfBirth IS NOT NULL BEGIN

INSERT INTO _MemberProfileCharacterValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 1, @.DateOfBirth)

END

IF @.Male = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 1)

END

IF @.Female = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 3)

END

IF @.Single = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 8)

END

IF @.Married = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 7)

END

IF @.Divorced = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 9)

END

IF @.Widowed = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 10)

END

IF @.Height = '1.22' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 3, 85)

END

IF @.Weight = 'x' BEGIN

INSERT INTO _MemberProfileNumericValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 4, @.Weight)

END

IF @.Absentism = '1' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 158)

END

IF @.Absentism = '2' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 159)

END

IF @.Absentism = '3' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 160)

END

IF @.Absentism = '4' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 161)

END

SET @.numValues = @.numValues - 1

END

Kind Regards

Carel Greaves

|||

As far as i can see, your proc looks fine and there aren't any glaring errors. Which leads me to believe its the data that is causing the problems.


I'd definitely follow Louis' advice and add print statements before you go into the IF blocks so you can check the data against that of the table.

PRINT @.NumValues

PRINT @.CurrentValue

PRINT @.Absentism

....

|||My first guess is your values for @.Male, @.Female, etc are NULL.

Add some commands like this and see what you get:

IF @.Male IS NULL
PRINT '@.Male is NULL'
ELSE
PRINT '@.Male=['+@.Male+']'

My SP works on 2005 bit not on 2000 it doesn''t step through my code.

Hi

I have a SP that works on SQL 2000 but not on 2005

It is just suppose to step through my code and insert values into tables where it finds the "ticked" values

here is apiece of my code. I hope it Helps.

Code Snippet

INSERT INTO Members (ClientID, Name, Surname, Email, Username, Password, Active, WlcSent)

SELECT ClientID, [Name], Surname, Email, Username, Password, Active, [Welcome Sent]

FROM StageMemberUploading

WHERE ID = @.numValues

SET @.CurrentValue = (SELECT SCOPE_IDENTITY())

IF @.ClientID IS NOT NULL BEGIN

INSERT INTO MemberUsergroup (MemberID, ClientID, UsergroupID)

VALUES (@.CurrentValue, @.ClientID, @.UsergroupID)

END

IF @.DateOfBirth IS NOT NULL BEGIN

INSERT INTO _MemberProfileCharacterValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 1, @.DateOfBirth)

END

-My Code Stops here

IF @.Male = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 1)

END

IF @.Female = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 3)

END

Any help would be greatly appreciated

Kind Regards

Carel greaves

Well, without knowing where you get the values of @.clientId or what the value was, there is no telling. No where in your code does the ClientId get set.

Can you add some print statements to your code to show what the values are? Preferrably before and after the IF statements, so you can see the value, and then if it actually got inside the block.

|||What do you mean "My Code Stops Here"? Are you getting an error? Or is it just not matching any of your IF statements as you expect?

Without seeing the entire SP and sample data, there is no telling what is causing your problem.

|||

Hi sorry, here is the whole procedure. Whe iu said my code stops here, it doesn't give me an error, it means that it doesn't run through the if statements, so it inserts the member's details into my members table and then it stops. That's all, doesn't look like it even touches my IF statements, and it doesn't give me any error codes.

Sorry about before, i was more confused, so i didn't know what data to put on the forum for help.

Here is all the code for my SP.

Code Snippet

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

ALTER PROCEDURE [dbo].[csp_MemberUploader]

AS

DECLARE @.CurrentValue INT

DECLARE @.numValues INT

DECLARE @.MaxValue INT

SELECT @.numValues = COUNT(ID), @.MaxValue = MAX(ID)

FROM StageMemberUploading

WHILE @.numValues <> 0

BEGIN

DECLARE @.DateOfBirth DATETIME

DECLARE @.Male VARCHAR(50)

DECLARE @.Female VARCHAR(50)

DECLARE @.Single VARCHAR(50)

DECLARE @.Married VARCHAR(50)

DECLARE @.Divorced VARCHAR(50)

DECLARE @.Widowed VARCHAR(50)

DECLARE @.Height VARCHAR(50)

DECLARE @.Weight VARCHAR(50)

DECLARE @.Absentism VARCHAR(50)

DECLARE @.UsergroupID INT

DECLARE @.ClientID INT

SELECT @.DateOfBirth = [Date of birth],

@.Male = [Male],

@.Female = [Female],

@.Single = [Single],

@.Married = [Married],

@.Divorced = [Divorced],

@.Widowed = [Widowed],

@.Height = [Height],

@.Weight = [Weight],

@.Absentism = [Absentism],

@.UsergroupID = UsergroupID,

@.ClientID = ClientID

FROM StageMemberUploading

WHERE ID = @.numValues

INSERT INTO Members (ClientID, Name, Surname, Email, Username, Password, Active, WlcSent)

SELECT ClientID, [Name], Surname, Email, Username, Password, Active, [Welcome Sent]

FROM StageMemberUploading

WHERE ID = @.numValues

SET @.CurrentValue = (SELECT SCOPE_IDENTITY())

IF @.ClientID IS NOT NULL BEGIN

INSERT INTO MemberUsergroup (MemberID, ClientID, UsergroupID)

VALUES (@.CurrentValue, @.ClientID, @.UsergroupID)

END

IF @.DateOfBirth IS NOT NULL BEGIN

INSERT INTO _MemberProfileCharacterValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 1, @.DateOfBirth)

END

IF @.Male = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 1)

END

IF @.Female = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 2, 3)

END

IF @.Single = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 8)

END

IF @.Married = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 7)

END

IF @.Divorced = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 9)

END

IF @.Widowed = 'x' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 6, 10)

END

IF @.Height = '1.22' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 3, 85)

END

IF @.Weight = 'x' BEGIN

INSERT INTO _MemberProfileNumericValues (MemberID, OptionID, OptionValue)

VALUES (@.CurrentValue, 4, @.Weight)

END

IF @.Absentism = '1' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 158)

END

IF @.Absentism = '2' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 159)

END

IF @.Absentism = '3' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 160)

END

IF @.Absentism = '4' BEGIN

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

VALUES (@.CurrentValue, 15, 161)

END

SET @.numValues = @.numValues - 1

END

Kind Regards

Carel Greaves

|||

As far as i can see, your proc looks fine and there aren't any glaring errors. Which leads me to believe its the data that is causing the problems.


I'd definitely follow Louis' advice and add print statements before you go into the IF blocks so you can check the data against that of the table.

PRINT @.NumValues

PRINT @.CurrentValue

PRINT @.Absentism

....

|||My first guess is your values for @.Male, @.Female, etc are NULL.

Add some commands like this and see what you get:

IF @.Male IS NULL
PRINT '@.Male is NULL'
ELSE
PRINT '@.Male=['+@.Male+']'