473,382 Members | 1,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Delete

OuTCasT
374 256MB
I have a table called students. with a column called creditsavailable.
now for example say that the specific student has 500 credits and i would like to delete 250 from it.
what delete statement would i use to delete 250 credits from the 500 credits that the student has >???
Jan 2 '08 #1
12 1373
amitpatel66
2,367 Expert 2GB
I have a table called students. with a column called creditsavailable.
now for example say that the specific student has 500 credits and i would like to delete 250 from it.
what delete statement would i use to delete 250 credits from the 500 credits that the student has >???
try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. UPDATE students set creditsavailable = creditsavailable - 250;
  3.  
  4.  
Jan 2 '08 #2
OuTCasT
374 256MB
THANKS....
I never knew a person could do that, i have never used something like that before.....thanks again.
Jan 2 '08 #3
OuTCasT
374 256MB
I have another problem thati u can mayb help me out with
//

I use a BULK INSERT to insert a entire .csv file of students, name, surname etc

now this will only be done like every 2 months or so, say the 100 students bought more credits and the admin doesnt want to do the changes 1 at a time, using the bulk insert how can u replace the credit values without duplicating the
students ???

the PK for the table is the StudentID, now in the CSV file i have 2 columns which are StudentID and CreditsAvailable, now is it possible just to update the credits for those students ???

PLEASE HELP :(
Jan 2 '08 #4
ck9663
2,878 Expert 2GB
it really depends on the design of your system. remember that when you update your table the current value will be overwritten by the new one. if you need to refer to those values it'll be gone unless you have a backup. in some dbdesign, they use table or column naming convention to preserve this value.

if we're just follow what you posted as your requirement, i would recommend you just create a stored proc that will read the text file. bcp-into a some sort of transaction table (ie credityyyymm). then do a UPDATE...FROM

hope this helps

-- CK
Jan 3 '08 #5
jamesd0142
469 256MB
You can do something like this if it helps:

Expand|Select|Wrap|Line Numbers
  1. update <TableName>
  2. set <col01= '100' where <col02> in ('a', 'b')
  3.  
so where col02 = "a" or "b" col01 will be set to "100"

any help?
Jan 3 '08 #6
amitpatel66
2,367 Expert 2GB
I have another problem thati u can mayb help me out with
//

I use a BULK INSERT to insert a entire .csv file of students, name, surname etc

now this will only be done like every 2 months or so, say the 100 students bought more credits and the admin doesnt want to do the changes 1 at a time, using the bulk insert how can u replace the credit values without duplicating the
students ???

the PK for the table is the StudentID, now in the CSV file i have 2 columns which are StudentID and CreditsAvailable, now is it possible just to update the credits for those students ???

PLEASE HELP :(
You can create a procedure which will do the following task to achieve your requirement:

1. Read a record from the flat file
2. Check if the student id in the record is already available in the table.
3. If point 2 satisfies, then update the credit available for that student in the table
4. If point 2 does not satisfy, then do an insert wof the particular record.

In this case, bulk insert/update will not be possible.
If you want to perform BULK INSERT or BULK UPDATE, then you need to do the following also:

1. Read through file and find out the studentids that are there in the table and place them in one array.
2. Find out student ids that are not there in the table.
3. Use theses arrays and perform BULK UPDATE for point 1 and BULK INSERT for point 2.

I hope this helps!!
Jan 3 '08 #7
OuTCasT
374 256MB
You can create a procedure which will do the following task to achieve your requirement:

1. Read a record from the flat file
2. Check if the student id in the record is already available in the table.
3. If point 2 satisfies, then update the credit available for that student in the table
4. If point 2 does not satisfy, then do an insert wof the particular record.
Hi, not to clued up with Stored Procedures, but i know what u are aiming at.
thanks....
Jan 3 '08 #8
OuTCasT
374 256MB
it really depends on the design of your system. remember that when you update your table the current value will be overwritten by the new one. if you need to refer to those values it'll be gone unless you have a backup. in some dbdesign, they use table or column naming convention to preserve this value.

if we're just follow what you posted as your requirement, i would recommend you just create a stored proc that will read the text file. bcp-into a some sort of transaction table (ie credityyyymm). then do a UPDATE...FROM

hope this helps

-- CK
Yeah i dont need to refer to the previous values.
Say the students pay it into the colleges bank acc, and they make a .csv file with all the StudentID's and Credits in it.
The admin person wld just have to upload the .csv file with the system, first the .csv file will have to be inserted into a table for viewing, otherwise the new total wld just update the old total, instead of adding the new total to the already existing total....if the total was not on 0.

i did a manual version

2 textboxes and a button

UPDATE [credit] SET [credit] = [credit] + ' " & txtCredit.text & " ' WHERE studentid = ' " & txtStudentID & " '

but that wld be manual.....
Jan 3 '08 #9
ck9663
2,878 Expert 2GB
Yeah i dont need to refer to the previous values.
Say the students pay it into the colleges bank acc, and they make a .csv file with all the StudentID's and Credits in it.
The admin person wld just have to upload the .csv file with the system, first the .csv file will have to be inserted into a table for viewing, otherwise the new total wld just update the old total, instead of adding the new total to the already existing total....if the total was not on 0.

i did a manual version

2 textboxes and a button

UPDATE [credit] SET [credit] = [credit] + ' " & txtCredit.text & " ' WHERE studentid = ' " & txtStudentID & " '

but that wld be manual.....
MANUAL:
1. view the CSV file using some sort of a text editor/viewer (ie EXCEL)
2. using DTS, upload the CSV into some sort of transaction table using a predefined table naming convention. this can be used as your history and will be easier for your table/file management.
3. create a procedure that you can re-use everytime, something like:

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE UpdateCreditMasterTable (@yyyymm as nvarchar)
  2. AS
  3.   declare @sqlstring as varchar(5000)
  4.  
  5.  if exists(select 1 from sysobjects where name = "TRANS" + @yyyy)
  6.    BEGIN
  7.      set @sqlstring = "UPDATE CreditMasterTable
  8.                             set CREDIT = CreditColumnOnYourTransactionFile
  9.                             from TRANS" + @yyyymm + TransTable
  10.                            " WHERE CreditMasterTable.dbo.StudentID = TransTable.dbo.StudentID "
  11.       exec @sqlstring
  12.    END
  13. GO
  14.  
couple of considerations:

1. you might also want to consider a transaction based so that you can rollback if there are errors.
2. this is a one-time update, once overwritten, no way to go back to previous state, back-up your table.
3. i have not completely tested that stored proc (lazy me), but i hope you get the idea.

-- CK
Jan 3 '08 #10
OuTCasT
374 256MB
MANUAL:
1. view the CSV file using some sort of a text editor/viewer (ie EXCEL)
2. using DTS, upload the CSV into some sort of transaction table using a predefined table naming convention. this can be used as your history and will be easier for your table/file management.
3. create a procedure that you can re-use everytime, something like:

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE UpdateCreditMasterTable (@yyyymm as nvarchar)
  2. AS
  3.   declare @sqlstring as varchar(5000)
  4.  
  5.  if exists(select 1 from sysobjects where name = "TRANS" + @yyyy)
  6.    BEGIN
  7.      set @sqlstring = "UPDATE CreditMasterTable
  8.                             set CREDIT = CreditColumnOnYourTransactionFile
  9.                             from TRANS" + @yyyymm + TransTable
  10.                            " WHERE CreditMasterTable.dbo.StudentID = TransTable.dbo.StudentID "
  11.       exec @sqlstring
  12.    END
  13. GO
  14.  
couple of considerations:

1. you might also want to consider a transaction based so that you can rollback if there are errors.
2. this is a one-time update, once overwritten, no way to go back to previous state, back-up your table.
3. i have not completely tested that stored proc (lazy me), but i hope you get the idea.

-- CK

Error messages

Expand|Select|Wrap|Line Numbers
  1. Msg 137, Level 15, State 2, Procedure UpdateCreditMasterTable, Line 5
  2. Must declare the scalar variable "@yyyy".
  3. Msg 156, Level 15, State 1, Procedure UpdateCreditMasterTable, Line 10
  4. Incorrect syntax near the keyword 'WHERE'.
Jan 4 '08 #11
ck9663
2,878 Expert 2GB
try:


Expand|Select|Wrap|Line Numbers
  1.       CREATE PROCEDURE UpdateCreditMasterTable (@yyyymm as nvarchar)
  2.       AS
  3.        declare @sqlstring as varchar(5000)
  4.        if exists(select 1 from sysobjects where name = "TRANS" + @yyyymm)
  5.          BEGIN
  6.            set @sqlstring = "UPDATE CreditMasterTable
  7.                                   set CREDIT = CreditColumnOnYourTransactionFile
  8.                                   from TRANS" + @yyyymm + " TransTable WHERE CreditMasterTable.dbo.StudentID = TransTable.dbo.StudentID "
  9.             exec @sqlstring
  10.          END
  11.       GO
Jan 4 '08 #12
OuTCasT
374 256MB
try:


Expand|Select|Wrap|Line Numbers
  1.       CREATE PROCEDURE UpdateCreditMasterTable (@yyyymm as nvarchar)
  2.       AS
  3.        declare @sqlstring as varchar(5000)
  4.        if exists(select 1 from sysobjects where name = "TRANS" + @yyyymm)
  5.          BEGIN
  6.            set @sqlstring = "UPDATE CreditMasterTable
  7.                                   set CREDIT = CreditColumnOnYourTransactionFile
  8.                                   from TRANS" + @yyyymm + " TransTable WHERE CreditMasterTable.dbo.StudentID = TransTable.dbo.StudentID "
  9.             exec @sqlstring
  10.          END
  11.       GO
that works....shot

what i deducted from my problem is that i need a stored proc that when updating the table with a .csv file with students in the .csv file that already exist in the table.....what the proc must do is check the table for studentID that already exist and then update there credits adding the credit already available to the new credits, otherwise if the studentID does not exist create the student.
Jan 4 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dave | last post by:
Hello all, In the code below, I see the following output: base::operator new(size_t, int) base::base() base::~base() base::operator delete(void *) In the case of an exception being thrown...
1
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there...
3
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. I am...
1
by: Douglas Peterson | last post by:
class Allocator { public: virtual void * Alloc(size_t) = 0; virtual void * Free(void*) = 0; }; class Object { public:
2
by: Dave | last post by:
Hello all, I'd like to find a source on the web that discusses, in a comprehensive manner and in one place, everything about new / delete. It should include overloading operator new, the new...
3
by: silver360 | last post by:
Hello, I'm trying to create a basic Heap manager and i have some question about new/delete overloading. The following code give me this output : >> $./heap >> registered : 0x804d098 >>...
9
by: rohits123 | last post by:
I have an overload delete operator as below ////////////////////////////////// void operator delete(void* mem,int head_type) { mmHead local_Head = CPRMemory::GetMemoryHead(head_type);...
10
by: jeffjohnson_alpha | last post by:
We all know that a new-expression, foo* a = new foo() ; allocates memory for a single foo then calls foo::foo(). And we know that void* p = ::operator new(sizeof(foo)) ; allocates a...
15
by: LuB | last post by:
I am constantly creating and destroying a singular object used within a class I wrote. To save a bit of time, I am considering using 'placement new'. I guess we could also debate this decision -...
29
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I remembered delete is implemented through operator overloading, but I am not quite clear. Could anyone recommend some links about how delete is implemented so that I can...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.