Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Truncate Question

 
   Database Forums (Home) -> Server RSS
Next:  Only the title shows  
Author Message
Granville3

External


Since: Oct 05, 2004
Posts: 5



(Msg. 1) Posted: Mon Jun 13, 2005 7:01 am
Post subject: Truncate Question
Archived from groups: microsoft>public>sqlserver>server (more info?)

Good day everyone

I have two SQL tables. One is a "Data" table in it with the days in the
dd/mm/yyy format.

Another "Time" table has the
dd/mm/yyy , Month, Quarter , Year in it.

I want to truncate the "Data" table but only where the Month is equal to
current month.
Rather than putting in a string "manually" I want the truncate statement to
pick up today’s date, look in the "Time" table, pick up the month that
current day belongs to and truncate all those days out of the "Data" table.

I've not even started so any ideas will be welcomed?

Thanks

Granville

 >> Stay informed about: Truncate Question 
Back to top
Login to vote
Jens Süßmeyer

External


Since: Apr 13, 2005
Posts: 67



(Msg. 2) Posted: Mon Jun 13, 2005 10:55 am
Post subject: Re: Truncate Question [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Delete from SomeTable
Where
MONTH(Datecol) = MONTH(Getdate()) AND
YEAR(Datecol) = YEAR(Getdate())

??

--
HTH, Jens Suessmeyer.

---
<a rel="nofollow" style='text-decoration: none;' href="http://www.sqlserver2005.de" target="_blank">http://www.sqlserver2005.de</a>
---
"Granville" schrieb im Newsbeitrag

 > Good day everyone
 >
 > I have two SQL tables. One is a "Data" table in it with the days in the
 > dd/mm/yyy format.
 >
 > Another "Time" table has the
 > dd/mm/yyy , Month, Quarter , Year in it.
 >
 > I want to truncate the "Data" table but only where the Month is equal to
 > current month.
 > Rather than putting in a string "manually" I want the truncate statement
 > to
 > pick up today's date, look in the "Time" table, pick up the month that
 > current day belongs to and truncate all those days out of the "Data"
 > table.
 >
 > I've not even started so any ideas will be welcomed?
 >
 > Thanks
 >
 > Granville
 >

 >> Stay informed about: Truncate Question 
Back to top
Login to vote
Jacco Schalkwijk1

External


Since: Jun 02, 2004
Posts: 118



(Msg. 3) Posted: Mon Jun 13, 2005 11:55 am
Post subject: Re: Truncate Question [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

TRUNCATE TABLE applies to the whole table only. You can't apply a where
clause with a TRUNCATE TABLE.

For what you want to do you need to use DELETE, something like:

DELETE d
FROM data d
INNER JOIN time t1
ON d.day = t1.day
INNER JOIN time t2
ON t1.Month = t2.Month
AND t1.Year = t2.Year
WHERE t2.day = CONVERT(CHAR(Cool, GETDATE(), 112)

--
Jacco Schalkwijk
SQL Server MVP


"Granville" wrote in message

 > Good day everyone
 >
 > I have two SQL tables. One is a "Data" table in it with the days in the
 > dd/mm/yyy format.
 >
 > Another "Time" table has the
 > dd/mm/yyy , Month, Quarter , Year in it.
 >
 > I want to truncate the "Data" table but only where the Month is equal to
 > current month.
 > Rather than putting in a string "manually" I want the truncate statement
 > to
 > pick up today's date, look in the "Time" table, pick up the month that
 > current day belongs to and truncate all those days out of the "Data"
 > table.
 >
 > I've not even started so any ideas will be welcomed?
 >
 > Thanks
 >
 > Granville
 >
 >> Stay informed about: Truncate Question 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
truncate all tables - Hi! This is probably a very stupid question but I am using this script to truncate all tables within a specific database but I am getting this error message: Server: Msg 170, Level 15, State 1, Line 10 Line 10: Incorrect syntax near '@user_tbl'. Not sur...

Truncate table and rollback - I just tested on a very small table that if you do begin tran truncate table tablename you can rollback the changes! I don't know why, but I always assumed truncate table meant "gone forever". But I didn't try this on a larger table so what ...

Difference between Delete,Truncate and Drop - Need exact difference between delete,truncate and drop table. Thanks in advance

A new @@Error question. - Here is what I really need to accomplish: CREATE TABLE [dbo].[Table1] ( [c1] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY] GO CREATE TABLE [dbo].[Table2] ( [c1] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON..

silly question but.... - In SQL Server Business Intelligence Development Studio, how do i create subfolders in my projects ? when i deploy they always go to the root of my report server, where i have to move the reports into the relevant folders, however once i deploy again ..
   Database Forums (Home) -> Server All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]