DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to use the EXISTS keyword in conditional expressions?

The following Microsoft SQL Server 2008 T-SQL scripts demonstrate the use of EXISTS in conditional expressions.

-- T-SQL check table existence before dropping view or table
-- Create test table with SELECT INTO
USE AdventureWorks2008;
SELECT * INTO Product1 FROM AdventureWorks2008.Production.Product
GO
-- (504 row(s) affected)
CREATE VIEW vProduct1 AS SELECT * FROM Product1
GO
IF  EXISTS (SELECT * FROM sys.views
            WHERE object_id = OBJECT_ID(N'[dbo].[vProduct1]'))
DROP VIEW [dbo].[vProduct1]
GO
IF  EXISTS (SELECT * FROM sys.objects
            WHERE object_id = OBJECT_ID(N'[dbo].[Product1]')
              AND type in (N'U'))

DROP TABLE [dbo].[Product1]
GO

-- DROP stored procedure if exists

IF EXISTS ( SELECT *

                  FROM sys.objects

                  WHERE object_id = OBJECT_ID(N'[dbo].[uspCustomerListByState]')

                              AND TYPE IN (N'P',N'PC'))

DROP PROCEDURE [dbo].[uspCustomerListByState]

GO

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE