|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help with Stored Procedure needed ASAP!
Hello,
I'm new to SQL. I wrote this Stored Procedure but it does not work. When I'm executing it I get these errors: Server: Msg 170, Level 15, State 1, Procedure Test, Line 12 Line 12: Incorrect syntax near '='. Server: Msg 170, Level 15, State 1, Procedure Test, Line 15 Line 15: Incorrect syntax near ')'. Server: Msg 170, Level 15, State 1, Procedure Test, Line 19 Line 19: Incorrect syntax near '='. Server: Msg 170, Level 15, State 1, Procedure Test, Line 24 Line 24: Incorrect syntax near '=' Can anyone please help me with that? Thank you in advance. CREATE PROCEDURE Test As BEGIN TRANSACTION Select PVDM_DOCS_1_5.DOCINDEX1, TableTest.DOCINDEX2, TableTest.DOCINDEX3, TableTest.DOCINDEX4 From PVDM_DOCS_1_5, TableTest WHERE TableTest.DOCINDEX1 = PVDM_DOCS_1_5.DOCINDEX1 AND (TableTest.DOCINDEX2 Is NULL or TableTest.DOCINDEX2 ='' OR TableTEst.DOCINDEX3 Is NULL or TableTest.DOCINDEX3 ='' or TableTest.DOCINDEX4 is NULL or TableTEst.DOCINDEX4 = ''); IF TableTest.DOCINDEX2 is NULL or TableTest.DOCINDEX2 = '' UPDATE TableTest.DOCINDEX2 = DOCINDEX2 WHERE (DOCINDEX1 IN (SELECT DOCINDEX1 FROM PVDM_DOCS_1_5)) END IF If TableTest.DOCINDEX3 is NULL or TableTest.DOCINDEX3 = '' UPDATE TableTest.DOCINDEX3 = PVDM_DOCS_1_5.DOCINDEX3 WHERE (DOCINDEX1 IN (SELECT DOCINDEX1 FROM PVDM_DOCS_1_5)) END IF If TableTest.DOCINDEX4 is NULL or TableTest.DOCINDEX4 = '' UPDATE TableTest.DOCINDEX4 = PVDM_DOCS_1_5.DOCINDEX4 WHERE (DOCINDEX1 IN (SELECT DOCINDEX1 FROM PVDM_DOCS_1_5)) END IF; DELETE PVDM_DOCS_1_5 WHERE DOCINDEX1 = DOCINDEX1 IF (@@ERROR <> 0) GOTO on_error COMMIT TRANSACTION -- return 0 to signal success RETURN (0) on_error: ROLLBACK TRANSACTION -- return 1 to signal failure RETURN (1) GO |
|
#2
|
||||
|
||||
|
line 12 is UPDATE TableTest.DOCINDEX2 = DOCINDEX2
first of all, you update a table, not a column, and secondly, you forgot the SET keyword |
|
#3
|
||||
|
||||
|
also, this statement --
DELETE PVDM_DOCS_1_5 WHERE DOCINDEX1 = DOCINDEX1 will delete all rows from the table, because every value is equal to itself well, perhaps excluding rows where DOCINDEX1 is null, because null is not equal to itself i strongly urge you to back up your tables before you begin testing your procedure |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Help with Stored Procedure needed ASAP! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|