May 4, 2015 at 3:37 pm
what will be the best way to write this code? I have the following code:
BEGIN
declare
status_sent as nvarchar(30)
SET NOCOUNT ON;
case status_sent =( select * from TableSignal
where ID=(SELECT id_
FROM [P_Database].[dbo].[Package]
where SerialNumber=@Pallet ) and SignalId=23)
when is null then 'Signal not send'
when not null then 'Signal Sent'
end
then if Signal Sent.... do the following query:
Select * from package.....
if signal not sent don't do anything
any help will be appreciate it.....on how to evaluate the first query with the 2 options and based on that
options write the next query.
May 4, 2015 at 5:18 pm
If I were to do this query, and I understand it correctly, I would do it like this:
SET NOCOUNT ON;
if exists(
select *
from tablesignal
inner join [P_Database].[dbo].[Package]
on tablesignal.ID = package.id_
where tablesignal.signalid = 23
and package.serialnumber = @Pallet
)
select package...
frompackage
If you needed to do something else in the second query (more than just a select statement if the sent signal exists), wrap that last select statement in BEGIN and END statements.
Does this response apply to your question?
May 6, 2015 at 9:02 am
It works, thank you so much!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply