October 5, 2005 at 10:11 am
Hi!
I need to build something like DialogBox in my stored procedure (without break it in two) such as :
CREATE PROCEDURE myproc
as
select * into tab1 from tab2
if exists( select * from tab1 where date_1 is null)
begin
-- HERE I NEED DECISION FROM USER:
-- MsgBOX ('Data_1 can't be empty!
-- IF
....
Any idea??
October 5, 2005 at 10:15 am
Sorry,
Stored procedures do not work that way.
your pseudo code is not very clear. can you elaborate on your problem
Thanks.
October 5, 2005 at 10:17 am
Also, those kind of questions must be asked before the user hits execute. If you need input after something execute, then you need to ask that question after the proc has finished running. Then call another procedure has needed.
October 5, 2005 at 10:24 am
I mean any extend procedure (such as CMDSHELL ) that can return any value as input in my procedure.
Once more :
CREATE PROCEDURE myproc
as
select * into tab1 from tab2
if exists( select * from tab1 where date_1 is null)
begin
-- HERE I NEED DECISION FROM USER:
-- MsgBOX ('Date_1 can't be empty! "DELETE" or "UPDATE"?')
-- IF "DELETE" -> DELETE FROM tab1 where date_1 is NULL
-- IF "UPDATE" -> UPDATE tab1 set date_1=GetDate() where date_1 is NULL
...
October 5, 2005 at 11:25 am
Let me make this clear once and for all : THAT'S NOT THE WAY TO CODE.
What do you need to do exactly?
October 5, 2005 at 1:19 pm
The answer is absolutely not an interactive stored procedure. You could use a DTS or SSIS package with an InputBox in a script task, a web page, a .vbs script with ADO, or many other ways. Maybe another parameter with the answer, or two procedures where one assumes the answer is yes and the other assumes no.
But don't even think about putting something interactive in a stored procedure.
October 5, 2005 at 4:31 pm
Create 2 procedures.
1st - to check if there are rows with NULL in DATA_1. Set @RETURN_VALUE for this SP according to the result.
You can just RETURN value of (select COUNT(*) ...WHERE DATA_1 IS NULL)
Than if there is no NULL values (@RETURN_VALUE = 0) - go straight to next SP to copy data.
If there are NULLs (@RETURN_VALUE > 0) ask client what to do and pass the answer to SP as a parameter.
It could be the same SP No.2 starting with something like this:
If @Action = 'DELETE'
DELETE FROM ...
WHERE DATA_1 IS NULL
IF @Action = 'UPDATE'
UPDATE....
WHERE DATA_1 IS NULL
IF there are no NULL rows it will do nothing with any value of @Action supplied.
_____________
Code for TallyGenerator
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply