Home > Archive > MS SQL Server > August 2005 > How to write this stored procedure...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to write this stored procedure...
dbuchanan

2005-08-23, 8:23 pm

What makes this stored procedure especially difficult for me is that I
don't know how to write SQL so that it will return the record whether
or not the field c.cmVoltage_K is null (IOW whether or not the inner
join is invalid).

The way it works is that the field c.cmVoltage_k stores the key value
for a lookup table.

The system automatically enters the record before the user has a chance
to perform the selection in a combobox that gives the value to the
field c.cmVoltage.

When c.cmVoltage_k is null the record will not display so the user has
no access to the record.

I want a record to to display in both cases. How do I do that?

=== The stored procedure ===

SELECT
c.pkComponentId,
c.fkDevice,
c.fkComponentType,
c. ComponentDescription
,
c. QuanSharingConfigura
tion,
c.QuanActuations,
c.cmVoltage_k, -- stores the key for lkp104Voltage
v.Voltage, -- displays the values
c.cmUserNote,
c.cmCreatedOn,
c.cmCreatedBy,
c.cmEditedOn,
c.cmEditedBy,
c.cmrowversion

FROM tbl040Cmpt c
INNER JOIN lkp104Voltage v ON c.cmVoltage_k = v.pkVoltageId

WHERE
(c.fkDevice = @fkDevice)
AND c.fkComponentType = 1

Hugo Kornelis

2005-08-23, 8:23 pm

On 23 Aug 2005 14:30:34 -0700, dbuchanan wrote:

(snip)
>I want a record to to display in both cases. How do I do that?


Hi dbuchanan,

Change

> INNER JOIN lkp104Voltage v ON c.cmVoltage_k = v.pkVoltageId


to

LEFT OUTER JOIN lkp104Voltage v ON c.cmVoltage_k = v.pkVoltageId


Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
dbuchanan

2005-08-25, 9:23 am

Thank you!

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com