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.
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | FrankStarting Member
 
 
                                        3 Posts | 
                                            
                                            |  Posted - 2002-05-03 : 19:43:37 
 |  
                                            | I need to select a record if existsin 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_commandeinto qte_transfrom cardex_mpwhere eno_prod=no_produit_cardexSomeone can help..?Edited by - frank on 05/03/2002  21:26:29 |  |  
                                    | vganesh76Yak Posting Veteran
 
 
                                    64 Posts | 
                                        
                                          |  Posted - 2002-05-04 : 10:10:34 
 |  
                                          | Frank I saw the query on yesterday onlyPlease 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 regardsV.Ganeshvganesh@rediffmail.com |  
                                          |  |  |  
                                    | Arnold FribbleYak-finder General
 
 
                                    1961 Posts | 
                                        
                                          |  Posted - 2002-05-04 : 11:12:11 
 |  
                                          | SELECT COALESCE(Qte_commande, 0)INTO qte_transFROM cardex_mpRIGHT JOIN (SELECT 1 dummy) dummy  ON eno_prod = no_produit_cardex |  
                                          |  |  |  
                                    | FrankStarting Member
 
 
                                    3 Posts | 
                                        
                                          |  Posted - 2002-05-04 : 17:32:38 
 |  
                                          | Thanks every one, I resolve my problem.... |  
                                          |  |  |  
                                |  |  |  |