| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

12-13-11, 00:54
|
|
Registered User
|
|
Join Date: Sep 2011
Posts: 35
|
|
|
how to truncate just a column ?
|
|
Code:
credit | debit | cash_in_hand
------------------------------
100 100 0
consider this as my table where i have an requirement
where i need to truncate just the column cash_in_hand
but if i do something like this
Code:
delete from credit_debit_table where cash_in_hand = '0'
then it will delete the entire row with credit & debit information
but i need to delete only cash_in_hand column how to do that ?
note : i need to delete only data not the structure of cash_in_hand
|
|

12-13-11, 01:05
|
|
Registered User
|
|
Join Date: Feb 2004
Location: Bangalore, India
Posts: 242
|
|
update table set cash_in_hand = NULL ???
__________________
Cheers....
baburajv
|
|

12-13-11, 03:14
|
|
Registered User
|
|
Join Date: Apr 2008
Location: Iasi, Romania
Posts: 317
|
|
|
|
SQL Server (and all the RDBMSs too) stores data on a row-basis. This means that your requirement does not have any sense. You can put the column data to NULL as already suggested, but this is just a data approach.
Unless your requirement is about storage space.
__________________
Florin Aparaschivei
Iasi, Romania
|
|

12-13-11, 12:17
|
|
Resident Curmudgeon
|
|
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
|
|
Quote:
Originally Posted by navedjobs
note : i need to delete only data not the structure of cash_in_hand
|
can you explain what you want to happen in terms of the real world as opposed to the database? What you are describing resembles "I want to paint that rain cloud red." which may be possible under some circumstances, but doesn't make much sense and seems like it would require far more effort than it might justify.
If we could understand what you're trying to accomplish, we can probably offer you a good answer. Based on your description of your problem so far, baburajv has offered the best answer I can imagine.
-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
|
|

12-14-11, 10:34
|
|
Registered User
|
|
Join Date: Sep 2006
Location: Surrey, UK
Posts: 448
|
|
A variable value like cash in hand ought not to be stored in a table. Create a view to show this as the difference between the credit and debit values, and that way you will always have the current value available.
__________________
10% of magic is knowing something that no-one else does. The rest is misdirection.
|
|

12-19-11, 13:53
|
|
World Class Flame Warrior
|
|
Join Date: Jun 2003
Location: Ohio
Posts: 11,732
|
|
weejas, that can be a very expensive query to run time after time. I'm all for dynamically calculating when possible, but performing the same expensive calculations time after time on historical data, always getting the exact same result, begs for storing the data in the row.
__________________
If it's not practically useful, then it's practically useless.
blindman
www.chess.com: "sqlblindman"
|
|

12-19-11, 14:56
|
|
Registered User
|
|
Join Date: Sep 2006
Location: Surrey, UK
Posts: 448
|
|
This is true. However, it depends on how many transactions there are and how many times the information is required on a daily basis as to whether the performance hit will be a deal-breaker. For example, I work with two ERPSs, and neither of them store the stock on hand in the inventory.
Also, whether you're running a query over the whole table to sum transactions for display or running a query over the whole table to sum transactions for storage, you're still running the query over the same table.
__________________
10% of magic is knowing something that no-one else does. The rest is misdirection.
|
|

12-20-11, 15:33
|
|
World Class Flame Warrior
|
|
Join Date: Jun 2003
Location: Ohio
Posts: 11,732
|
|
Quote:
Originally Posted by weejas
Also, whether you're running a query over the whole table to sum transactions for display or running a query over the whole table to sum transactions for storage, you're still running the query over the same table.
|
Do I need to point out that you run it only once for storage, and it can be performed during off-hours?
__________________
If it's not practically useful, then it's practically useless.
blindman
www.chess.com: "sqlblindman"
|
|

12-21-11, 04:17
|
|
Registered User
|
|
Join Date: Sep 2006
Location: Surrey, UK
Posts: 448
|
|
And do I need to point out that if you run such a query overnight, your balances will not reflect any transactions since then? :P
There are pros and cons to both approaches. I favour calculating such totals as and when they are required, but I accept that it is possible to store them too, and in some cases is preferable.
__________________
10% of magic is knowing something that no-one else does. The rest is misdirection.
|
|

01-09-12, 12:54
|
|
World Class Flame Warrior
|
|
Join Date: Jun 2003
Location: Ohio
Posts: 11,732
|
|
Apparently I need to point out that it need be run across the table only once, for existing data.
A trigger or procedure code can keep individual records updated, very efficiently.
Apparently, that needed to be pointed out.
__________________
If it's not practically useful, then it's practically useless.
blindman
www.chess.com: "sqlblindman"
|
|

01-09-12, 16:18
|
|
Window Washer
|
|
Join Date: Nov 2002
Location: Jersey
Posts: 10,303
|
|
Quote:
Originally Posted by baburajv
update table set cash_in_hand = NULL ???
|
ding...ding...ding...ding....we have a winner
Johnny, tell'em what he's won
|
|

01-10-12, 12:49
|
|
World Class Flame Warrior
|
|
Join Date: Jun 2003
Location: Ohio
Posts: 11,732
|
|
Dong...dong...dong...dong...dong!
That answered his question, but did not solve his problem.
__________________
If it's not practically useful, then it's practically useless.
blindman
www.chess.com: "sqlblindman"
|
|

01-10-12, 13:00
|
|
Window Washer
|
|
Join Date: Nov 2002
Location: Jersey
Posts: 10,303
|
|
Quote:
Originally Posted by blindman
Dong...dong...dong...dong...dong!
That answered his question, but did not solve his problem.
|
Where did Oppie say that?
|
|

01-11-12, 12:07
|
|
World Class Flame Warrior
|
|
Join Date: Jun 2003
Location: Ohio
Posts: 11,732
|
|
Brett, read the post history.
The problem is how best to handle a calculated value such as cash in hand.
The discussion was whether CashInHand should be stored in the table at all.
This is clearly pertinent to both the original poster, and others who encounter this thread with similar problems.
__________________
If it's not practically useful, then it's practically useless.
blindman
www.chess.com: "sqlblindman"
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|