|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Yesterday @ 11:01 AM
Points: 382,
Visits: 1,102
|
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Wednesday, August 10, 2011 12:13 PM
Points: 307,
Visits: 565
|
|
Why would I get zero and zero when I run this set of queries on SQL 2005?
If it was easy, everybody would be doing it!;)
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Tuesday, December 11, 2012 9:07 AM
Points: 1,619,
Visits: 473
|
|
| Based on the queries supplied, you should get 1 and 1, because the first statement includes the wildcard at the beginning, so the # SHOULD be returned.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 11:10 AM
Points: 1,354,
Visits: 890
|
|
Rich (2/27/2009) Based on the queries supplied, you should get 1 and 1, because the first statement includes the wildcard at the beginning, so the # SHOULD be returned.
The answer says
"Table variable names inside tempdb starts with '#' followed by hex string"
In which case it wouldn't find it using the name
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 6:39 AM
Points: 2,013,
Visits: 2,841
|
|
This doesn't work on 2000 but it does on 2005.
Baseball is back!
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 11:54 AM
Points: 795,
Visits: 1,981
|
|
How many rows would this return? :) (yes...it's different)
use AdventureWorks go declare @tableA TABLE(col1 int, col2 int) go --stmt 1 select name from tempdb.sys.tables where name like '%tableA%' --stmt 2 select name from tempdb.sys.columns where name like 'col1%'
Gaby ________________________________________________________________ "In theory, theory and practice are the same. In practice, they are not." - Albert Einstein
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Tuesday, December 11, 2012 9:07 AM
Points: 1,619,
Visits: 473
|
|
Longy (2/27/2009)
Rich (2/27/2009) Based on the queries supplied, you should get 1 and 1, because the first statement includes the wildcard at the beginning, so the # SHOULD be returned.The answer says "Table variable names inside tempdb starts with '#' followed by hex string" In which case it wouldn't find it using the name
Oops. Too early in the AM.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 11:10 AM
Points: 1,354,
Visits: 890
|
|
Rich (2/27/2009)
Longy (2/27/2009)
Rich (2/27/2009) Based on the queries supplied, you should get 1 and 1, because the first statement includes the wildcard at the beginning, so the # SHOULD be returned.The answer says "Table variable names inside tempdb starts with '#' followed by hex string" In which case it wouldn't find it using the name Oops. Too early in the AM.
Yeah, I thought exactly the same thing at first, but after re-reading it spotted that!
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Wednesday, August 10, 2011 12:13 PM
Points: 307,
Visits: 565
|
|
Thanks, skjoldtc!
When you said that I checked my compatibility level on the database I ran the queries on and they were set to 80 which is why I got zeros when I ran the queries.
If it was easy, everybody would be doing it!;)
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 2:02 PM
Points: 6,367,
Visits: 8,228
|
|
Interesting.
I modified the supplied code to get the # of tempdb objects, and all tempdb table names:
use AdventureWorks go select count(*) from tempdb.sys.objects select name from tempdb.sys.tables --where name like '%tableA%' declare @tableA TABLE(col1 int, col2 int) --stmt 1 select name from tempdb.sys.tables --where name like '%tableA%' --stmt 2 select name from tempdb.sys.columns where name like 'col1%' select count(*) from tempdb.sys.objects
and I find that there are no new tables or objects between the two selects from sys.tables.
So I modified the sys.columns select to:
select sc.name [ColName], st.name [TableName] from tempdb.sys.columns sc INNER JOIN tempdb.sys.tables st ON st.object_id = sc.object_id where sc.name like 'col1%'
What I'm seeing is that the tablename for this table is already in use before the table is declared. I've even tried stopping and restarting the sql service for this instance.
What's up with this?
Wayne Microsoft Certified Master: SQL Server 2008 If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it! Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines, CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
|
|
|
|