I'm trying to create an if/else case in a stored procedure where if te record is not found, it returns blank values, and if it is found I get the real values. But when I try to execute the SP update I get column does not exist for the else clause (all columns starting with shift through sequence)
I'm sure this is a simple problem, and I apologize in advance. - USE [ADC]
-
GO
-
/****** Object: StoredProcedure [dbo].[getSchedule] Script Date: 10/20/2008 11:54:55 ******/
-
SET ANSI_NULLS ON
-
GO
-
SET QUOTED_IDENTIFIER ON
-
GO
-
-- =============================================
-
-- Author: Jeffrey Grace
-
-- Create date: 2008-10-16
-
-- Description: Gets scheduled data and returns to PLC
-
-- =============================================
-
ALTER PROCEDURE [dbo].[getSchedule]
-
-- Input
-
@facility char(2),
-
@line int,
-
@shiftin int,
-
-
--@sequence int,
-
-- Output
-
@shiftout int output,
-
@sequence int output,
-
@operator_num char(8) output,
-
@operator_name char(30) output,
-
@pack_num char(8) output,
-
@pack_name char(30) output,
-
@item1 char(15) output,
-
@item2 char(15) output,
-
@item3 char(15) output,
-
@item4 char(15) output,
-
@cutQty char(10) output,
-
@cutTime char(4) output
-
-
AS
-
BEGIN
-
SET NOCOUNT ON;
-
select top 1 shift, operator, pack, item1,
-
item2, item3, item4, cutQty, cutTime, sequence
-
from schedule where
-
facility=@facility and
-
line=@line and
-
shift=@shiftin
-
-
if @@ROWCOUNT = 0
-
BEGIN
-
set @shiftout=0
-
set @sequence=0
-
set @operator_num=''
-
set @operator_name=''
-
set @pack_num=''
-
set @pack_name=''
-
set @item1=''
-
set @item2=''
-
set @item3=''
-
set @item4=''
-
set @cutQty=''
-
set @cutTime=''
-
End
-
-
Else
-
BEGIN
-
set @shiftout=shift
-
set @operator_num = operator
-
set @pack_num = pack
-
set @item1 = item1
-
set @item2 = item2
-
set @item3 = item3
-
set @item4 = item4
-
set @cutQty = cutQty
-
set @cutTime = cutTime
-
set @sequence = sequence
-
-
select @operator_name = emp_name from operators where
-
emp_num=@operator_num
-
-
select @pack_name = emp_name from operators where
-
emp_num=@pack_num
-
END
-
END
1 10613 ck9663 2,878
Recognized Expert Specialist
SQL Server does not always work like DBF or recordset processing ;)
Try the following.....I did not test this for any error but you should get the idea of what I'm trying to say. Also, depending on your requirement, change the type of JOIN as necessary. - USE [ADC]
-
GO
-
/****** Object: StoredProcedure [dbo].[getSchedule] Script Date: 10/20/2008 11:54:55 ******/
-
SET ANSI_NULLS ON
-
GO
-
SET QUOTED_IDENTIFIER ON
-
GO
-
-- =============================================
-
-- Author: Jeffrey Grace
-
-- Create date: 2008-10-16
-
-- Description: Gets scheduled data and returns to PLC
-
-- =============================================
-
ALTER PROCEDURE [dbo].[getSchedule]
-
-- Input
-
@facility char(2),
-
@line int,
-
@shiftin int,
-
-
--@sequence int,
-
-- Output
-
@shiftout int output,
-
@sequence int output,
-
@operator_num char(8) output,
-
@operator_name char(30) output,
-
@pack_num char(8) output,
-
@pack_name char(30) output,
-
@item1 char(15) output,
-
@item2 char(15) output,
-
@item3 char(15) output,
-
@item4 char(15) output,
-
@cutQty char(10) output,
-
@cutTime char(4) output
-
-
AS
-
BEGIN
-
SET NOCOUNT ON;
-
-
select top 1 @shiftout=shift, @operator_num = operator, @pack_num = pack, @item1 = item1,
-
@item2 = item2, @item3 = item3, @item4 = item4, @cutQty = cutQty, @cutTime = cutTime, @sequence = sequence,
-
@operator_name = op_name.emp_name, @pack_name = pk_name.emp_name
-
from schedule s
-
left join operators op_name on emp_num = s.operator
-
left join operators pk_name on emp_num = s.pack
-
where facility=@facility and line=@line andshift=@shiftin
-
-
if @@ROWCOUNT = 0
-
select @shiftout=0, @sequence=0, @operator_num='',@operator_name='',@pack_num='',@pack_name='',@item1='',@item2='',@item3='',@item4='',@cutQty='', @cutTime=''
-
END
-
-
Happy coding!
-- CK
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Christian Seberino |
last post by:
I am looking at the ELSE home page and trying to figure out if I should
invest the time to learn about the ELSE minor mode for Emacs.
Is there any programmer out there using ELSE that is getting great
benefit from it?
What does ELSE minor-mode for Emacs do that is so great for you?
Chris
|
by: seberino |
last post by:
Tuples are defined with regards to parentheses ()'s as everyone knows.
This causes confusion for 1 item tuples since (5) can be interpreted
as a tuple OR as the number 5 in a mathematical expression
such as x = (5) * (4+6).
Wouldn't it have been better to define tuples with <>'s or {}'s or
something else to avoid this confusion??
Perhaps ()'s are a good idea for some other reason I don't know?
|
by: Ron Adam |
last post by:
There seems to be a fair amount of discussion concerning flow control
enhancements lately. with, do and dowhile, case, etc... So here's my
flow control suggestion. ;-)
It occurred to me (a few weeks ago while trying to find the best way to
form a if-elif-else block, that on a very general level, an 'also'
statement might be useful. So I was wondering what others would think
of it.
|
by: phaser2001 |
last post by:
Hi all,
I have the below user-defined function on mssql 2000 and I can't work
out why i'm getting the following error:
-----
Server: Msg 156, Level 15, State 1, Procedure
fnCalculateOutworkerPaymentForBox, Line 15
Incorrect syntax near the keyword 'IF'.
Server: Msg 170, Level 15, State 1, Procedure
fnCalculateOutworkerPaymentForBox, Line 23
|
by: juglesh |
last post by:
"$string = isset($xyz) ? $xyz : "something else";"
Hello, someone gave code like this in another thread. I understand (by
inference) what it does, but have not found any documentation on this
type of syntax.
Any one have links to this shortuct(?) syntax and other types of
syntax?
thanks
| |
by: Jake Barnes |
last post by:
In the course of my research I stumbled upon this article by Alex
Russel and Tim Scarfe:
http://www.developer-x.com/content/innerhtml/default.html
The case is made that innerHTML should never be used. I'm wondering, If
I wanted all the content of BODY as a string, how else could I get
except through innerHTML?
|
by: Jim Michaels |
last post by:
C:\prj\quiz\withusers>php tareports.php
PHP Parse error: syntax error, unexpected T_ELSE in
C:\prj\quiz\withusers\tareports.php on line 205
this is the section of code.
if (isset($row4)) {
if (isset($row5)) { //answer given?
if ($row4==$row5) {
|
by: stef mientki |
last post by:
hello,
I've the idea that the "else" syntax is not always handled correctly,
or I'm overlooking something.
This pieces of code are automatic translation from another language,
sometimes it works, sometimes it doesn't ???
This piece of code works nice:
|
by: callumagus |
last post by:
Python Version 2.0
Windows Vista (I know, I know...)
Im very new to python and have only been doing it for two weeks.
print 'Type in lowercase!';
String_Var = raw_input ('Add, Divide, Multiply or Subtract? ');
if 'add' in String_Var:
|
by: creative1 |
last post by:
hi I am in strange problem. I have javascript for for validation. If I have any entry invalid it prompts me to corrrect it. All checks I have works fine. However, form does not response when there is no valid entry.
Here is my code. What do I do?
function validate(form) {
if ((form.clientName.value.length==0)||(form.clientName.value.length<3) ||(form.clientName.value.length>50)) {
mesg="You have entered...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |