Author |
Topic |
vmurali
Yak Posting Veteran
88 Posts |
Posted - 2006-08-19 : 03:02:18
|
Hi, I have a table containing 10 rows and I have to delete alternate rows in the table |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-08-19 : 03:11:07
|
Somthing like this Declare @var Table (col1 int identity(1,1),col2 int)Insert @varSelect 1 Union All Select 2 Union All Select 3 Union All Select 4 Union All Select 5 Union All Select 1 Union All Select 2 Union All Select 3 Union All Select 4 Union All Select 5 delete from @var Where Col1 % 2 =0Select * from @var Chirag |
 |
|
vmurali
Yak Posting Veteran
88 Posts |
Posted - 2006-08-19 : 03:37:27
|
Is it possible to do with a single query statement |
 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-08-19 : 03:48:14
|
its the single query only, i just showed by giving one sample. post the table strucutre with some sample data so it can be more clear Delete query is this much only. delete from @var Where Col1 % 2 =0Chirag |
 |
|
vmurali
Yak Posting Veteran
88 Posts |
Posted - 2006-08-19 : 03:54:43
|
I agree with you. But I wanted to do the same with a single SQL query.I am not supposed to do any other operation. I have to use only one delete statement |
 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-08-19 : 04:18:09
|
quote: Originally posted by vmurali I agree with you. But I wanted to do the same with a single SQL query.I am not supposed to do any other operation. I have to use only one delete statement
Yeah, this can be done only with one delete statement only, but for that you to give some more information, like table structure and same sample data, so we can have better understanding about it and help you out oks?Chirag |
 |
|
vmurali
Yak Posting Veteran
88 Posts |
Posted - 2006-08-19 : 04:46:00
|
candid canfname candlname1 sri kumaran2 sri kumaran3 val kumar4 shyam raman5 balaji k6 jack straw7 Jeel shetty8 ram mohan9 raja rangan10 ram shivadelete rows 1, 3, 5, 7, 9 |
 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-08-19 : 04:52:25
|
Delete From <TableName> Where CandId %2 <> 2Chirag |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-19 : 05:22:59
|
should be <> 0 not 2delete table where canid % 2 <> 0 KH |
 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-08-19 : 05:25:34
|
opps typo Chirag |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-19 : 05:34:52
|
quote: Originally posted by chiragkhabaria opps typo Chirag
 KH |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-08-21 : 00:44:14
|
quote: Originally posted by vmurali I agree with you. But I wanted to do the same with a single SQL query.I am not supposed to do any other operation. I have to use only one delete statement
Didnt you see the previous example correctly?Also alternate row has no meaning until you have unique key in the tableMadhivananFailing to plan is Planning to fail |
 |
|
|