Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL
I want to insert new costcode values in to table only if the new value dose not exsist in costcode column already.
if it exsists so
the TranDate and amount will be updated for the exsisting cost code.
 
Simply:
if costCode exsist then update tranDate and amount else insert new row with new valuse for each column.
 
CostCode TranDate Amount
04 31/01/2013 12:00:00 AM 262033.83
07 31/01/2013 12:00:00 AM 31579.87
01 31/01/2013 12:00:00 AM 980834.24
09 31/01/2013 12:00:00 AM 197237.28
 
I need help urgently.
 
please someone help me here.
thanks
Posted 21-Feb-13 8:02am
Comments
joshrduncan2012 at 21-Feb-13 14:11pm
   
Saying it's urgent doesn't get guarantee you a quicker reply. What have you tried so far to accomplish this task?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

if(Exists(select 1 from tbl where costcode=yourcode))
begin
 
your update sql;
end
 
else
 
begin
 
insert sql
 
end
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Query your table to see if your cost codes exists if it does then update the values that need to be updated, if it doesnt insert your new record.
 
SQL,
 
http://www.w3schools.com/sql/default.asp[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 397
1 OriginalGriff 350
2 thatraja 205
3 Emre Ataseven 165
4 Shai Vashdi 150
0 Sergey Alexandrovich Kryukov 8,894
1 OriginalGriff 5,200
2 Peter Leow 3,955
3 Maciej Los 3,535
4 Abhinav S 3,208


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid