How to incorporate an update statement into the following code

if exists(select 1
	from  ServiceRequest a
		LEFT JOIN   ServiceRequestAddFru b  ON b.SRequestID = a.SRequestID;
	where b.SRequestID is null)
begin
	set @BusinessRules_PreventDefault = 1
	set @Result_Focus = 'You must enter at least one Fru'
	set @Result_ShowViewMessage = 'Error You must enter a Fru'
end;

Open in new window


How do I incorporate this into this statement?

update ServiceRequest
set SRequestStatusID = '1'
where SRequestID = @SRequestID
set @Result_NavigateUrl = 'ServiceRequest.aspx'
JDay2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Since there's an IF EXISTS in the code example, explain the logic for whether that statement should be executed or not.
0
Éric MoreauSenior .Net ConsultantCommented:
you want to set the @Result_NavigateUrl variable only if a record has been updated?

why isn't your exists clause not the same as your where condition in the update statement?

My guess would be:

if exists(select 1
	from  ServiceRequest a
		LEFT JOIN   ServiceRequestAddFru b  ON b.SRequestID = a.SRequestID;
	where b.SRequestID is null)
begin
update ServiceRequest
 set SRequestStatusID = '1'
 where SRequestID = @SRequestID
 set @Result_NavigateUrl = 'ServiceRequest.aspx' 
	set @BusinessRules_PreventDefault = 1
	set @Result_Focus = 'You must enter at least one Fru'
	set @Result_ShowViewMessage = 'Error You must enter a Fru'
end;

Open in new window

0
JDay2Author Commented:
Basically,

You create the header row  (ServiceRequest)
Next there is a submit button on page

if you hit submit before any frus are added then I need it to show message
if you have frus then it should update the status and set the page
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Éric MoreauSenior .Net ConsultantCommented:
that seems to be your ASP.Net logic. What you have shown before is TSQL code. SQL won't show a message, it is the job of your ASP.Net application!
0
JDay2Author Commented:
Correct but I need it to stop and hold the message if no frus are selected.  Once frus are selected then hit submit and move to @Result_NavigateUrl = 'ServiceRequest.aspx' .

Right now it just goes to the ServiceRequest.aspx page I see the error but is quick.
0
Éric MoreauSenior .Net ConsultantCommented:
this logic has to be done in your ASP.Net code. TSQL code cannot be paused until somebody on the UI hits the answer
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.