remove data based upon criteria specified through arguments. : Select statement « Transact SQL « SQL Server / T-SQL Tutorial

SQL Server / T-SQL Tutorial
1. Query
2. Insert Delete Update
3. Table
4. Table Join
5. Data Types
6. Set Operations
7. Constraints
8. Subquery
9. Aggregate Functions
10. Date Functions
11. Math Functions
12. String Functions
13. Data Convert Functions
14. Analytical Functions
15. Sequence Indentity
16. View
17. Index
18. Cursor
19. Database
20. Transact SQL
21. Procedure Function
22. Trigger
23. Transaction
24. XML
25. System Functions
26. System Settings
27. System Tables Views
28. User Role
29. CLR
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
SQL Server / T-SQL Tutorial » Transact SQL » Select statement 
20. 16. 3. remove data based upon criteria specified through arguments.
7>
8>
9CREATE TABLE stores(
10>    stor_id        char(4)           NOT NULL,
11>    stor_name      varchar(40)           NULL,
12>    stor_address   varchar(40)           NULL,
13>    city           varchar(20)           NULL,
14>    state          char(2)               NULL,
15>    zip            char(5)               NULL
16)
17> GO
1insert stores values('1','B','56Ave.','Tustin',   'CA','92789')
2insert stores values('2','N','57St.', 'Los Gatos','CA','96745')
3insert stores values('3','T','67St.', 'Portland', 'OR','89076')
4insert stores values('4','F','89  St.', 'Fremont',  'CA','90019')
5> GO

(rows affected)

(rows affected)

(rows affected)

(rows affected)
1>
2>
3>     CREATE PROCEDURE prDeleteData    @chvTable VARCHAR(30),
4>                                       @chvWhereField VARCHAR(30= NULL,
5>                                       @chvWhereFieldDataType VARCHAR(30'CHAR',
6>                                       @chvOperator VARCHAR(2'=',
7>                                       @chvValue VARCHAR(30= NULL
8>     AS
9>     DECLARE @chvSQL VARCHAR(255), @chvQuotes CHAR(1)
10>     SELECT @chvSQL = 'DELETE ' + @chvTable
11>     IF NOT @chvWhereField IS NULL
12>             BEGIN
13>               SELECT @chvSQL = @chvSQL + ' WHERE ' + @chvWhereField + ' ' + @chvOperator + ' '
14>               SELECT @chvWhereFieldDataType = LOWER(RTRIM(@chvWhereFieldDataType))
15>               SELECT @chvQuotes = CASE @chvWhereFieldDataType
16>                      WHEN 'char' THEN 'y'
17>                      WHEN 'datetime' THEN 'y'
18>                      WHEN 'datetimn' THEN 'y'
19>                      WHEN 'smalldatetime' THEN 'y'
20>                      WHEN 'text' THEN 'y'
21>                      WHEN 'varchar' THEN 'y'
22>                      ELSE 'n'
23>               END
24>               IF @chvQuotes = 'y'
25>                      SELECT @chvSQL = @chvSQL + '''' + @chvValue + ''''
26>               ELSE
27>                      SELECT @chvSQL = @chvSQL + @chvValue
28>            END
29>     EXEC (@chvSQL)
30>     GO
1>
2>
3>     EXEC prDeleteData     @chvTable = 'stores',
4>             @chvWhereField = 'stor_name',
5>             @chvWhereFieldDataType = 'CHAR',
6>             @chvOperator = '=',
7>             @chvValue = 'News & Brews'
8>     GO

(rows affected)
1>
2>
3>     drop PROCEDURE prDeleteData;
4>     GO
1>
2> drop table stores;
3> GO
20. 16. Select statement
20. 16. 1. Optimized procedure to select earning authors.
20. 16. 2. Join tables in a procedure
20. 16. 3. remove data based upon criteria specified through arguments.
20. 16. 4. Stored Procedure to Retrieve a Customer's Most Recent Order
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.