Click here to Skip to main content
11,705,610 members (48,259 online)
Rate this: bad
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.

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.
Posted 21-Feb-13 8:02am
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
Please Sign up or sign in to vote.

Solution 2

if(Exists(select 1 from tbl where costcode=yourcode))

your update sql;



insert sql

Rate this: bad
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.


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

  Print Answers RSS
0 OriginalGriff 213
1 Sergey Alexandrovich Kryukov 160
2 Inimicos 60
3 ProgramFOX 50
4 Richard MacCutchan 45
0 OriginalGriff 9,053
1 Sergey Alexandrovich Kryukov 8,347
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,626

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100