Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Site Related Forums
 Article Discussion
 Select a record who may not exists

Author  Topic 

Frank
Starting Member

3 Posts

Posted - 2002-05-03 : 19:43:37
I need to select a record if exists
in a table and paste it into a variable, if not exist i need to give the value 0 to the variable. Here is the code i use and not work, returning a error when the record is not in the table.

select Qte_commande
into qte_trans
from cardex_mp
where eno_prod=no_produit_cardex

Someone can help..?




Edited by - frank on 05/03/2002 21:26:29

vganesh76
Yak Posting Veteran

64 Posts

Posted - 2002-05-04 : 10:10:34
Frank I saw the query on yesterday only
Please find if this code could help u,


Code:
insert into tablename
select
case
when exists (select qte_trans.column1
from qte_trans where qte_trans.column2=cardex.column2)
then (select qte_trans.column1 from qte_trans where qte_trans.column2=cardex.column2)
else '0'
end

from cardex



with regards
V.Ganesh
vganesh@rediffmail.com

Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2002-05-04 : 11:12:11
SELECT COALESCE(Qte_commande, 0)
INTO qte_trans
FROM cardex_mp
RIGHT JOIN (SELECT 1 dummy) dummy
ON eno_prod = no_produit_cardex


Go to Top of Page

Frank
Starting Member

3 Posts

Posted - 2002-05-04 : 17:32:38
Thanks every one, I resolve my problem....

Go to Top of Page
   

- Advertisement -