June 17, 2009 at 10:08 am
Hi, how can I create a query that is always looking for if a table exists or not, by a DTS
June 17, 2009 at 10:32 am
I'm not sure I understand your question. Do you want to write some TSql that will check for the existence of a table that you can then plug into your DTS Package?
June 17, 2009 at 10:46 am
what I want is to always check if a table exists, the code to know whether or not the table if it is, but as I get the sql constantly asking this consultation and the existence of the table, I do not know much English Sorry translation
June 17, 2009 at 10:59 am
Well, there are a couple of ways you can do this. Here is one of them:
IF OBJECT_ID('your_table_name') IS NOT NULL
-- Then do your stuff!
Hope that helps.
Chim Kalunta
June 17, 2009 at 11:22 am
You should be careful about just checking OBJECT_ID. You may have more than one object in the sys.objects table with that name. Take a look at http://msdn.microsoft.com/en-us/library/ms190324(SQL.90).aspx to see a list of all types.
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Employees]') AND type in (N'U'))
begin
do some stuff here
end
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply