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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Site Related Forums
 Article Discussion
 Select a record who may not exists
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Frank
Starting Member

3 Posts

Posted - 05/03/2002 :  19:43:37  Show Profile  Reply with Quote
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

India
64 Posts

Posted - 05/04/2002 :  10:10:34  Show Profile  Reply with Quote
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

United Kingdom
1961 Posts

Posted - 05/04/2002 :  11:12:11  Show Profile  Reply with Quote
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 - 05/04/2002 :  17:32:38  Show Profile  Reply with Quote
Thanks every one, I resolve my problem....

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000