Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete query help

Status
Not open for further replies.

sparkbyte

Technical User
Sep 20, 2002
879
US
How can this be made to handle multiple ID's to delete?

Code:
	DECLARE @RC int
	DECLARE @Reciept_Number varchar(max)
	DECLARE @ID_Number varchar(max)
	
	Set @Reciept_Number = 
		N'LIN1190136015'

-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
Set @ID_Number = (Select ID
					From dbo.LETTER_DETAILS t
						Inner Join (Select items From fn_Split(@Reciept_Number,',')) As SplitValues
							On t.RECEIPT_NUMBER = SplitValues.items)
--					Where 	CREATED_ON < dateadd(dd,-10,getdate()))
----	EXECUTE @RC = [NSC_SQL].[dbo].[usp_Delete_Case_By_ID] 
----	   @ID_Number
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
		Delete from dbo.LETTER_DETAILS
			Where Exists
				(Select ID
				From dbo.LETTER_DETAILS t
					Inner Join (Select items From fn_Split(@Reciept_Number,',')) As SplitValues
					On t.RECEIPT_NUMBER = SplitValues.items)

-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
		Select ID, NUMBER, RECEIPT_NUMBER, DS_NO, DATE_OF_MEMO, LETTER_TYPE, 
			CREATED_ON, CREATED_BY
		From dbo.LETTER_DETAILS t
			Inner Join (Select items From fn_Split(@Reciept_Number,',')) As SplitValues
				On t.RECEIPT_NUMBER = SplitValues.items
--		Where 	CREATED_ON < dateadd(dd,-1,getdate())
		Order by t.RECEIPT_NUMBER

Thanks

John Fuhrman
 
This doesn't work?

Code:
Delete dbo.LETTER_DETAILS
From   dbo.LETTER_DETAILS
       Inner Join dbo.fn_Split(@Reciept_Number, ',') As SplitValues
         On dbo.LETTER_DETAILS.RECEIPT_NUMBER = SplitValues.Items


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Guess I'll have to rethink what I was trying to do.


Thanks

John Fuhrman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top