|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 7:09 AM
Points: 31,
Visits: 103
|
|
| With the given SQL, @temp is an empty table, therefore count(1) will always return 0.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, March 15, 2013 10:35 AM
Points: 594,
Visits: 654
|
|
benkoskysa (3/3/2010) With the given SQL, @temp is an empty table, therefore count(1) will always return 0.
Not if you replace DATALENGTH with LEN in this query I have to try everything myself, take NOBODY's word for anything... yes, I am a trusting soul...
--Mileage may vary--
Peter Trast Microsoft Certified ...(insert many literal strings here) Microsoft Design Architect with Alexander Open Systems
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 7:09 AM
Points: 31,
Visits: 103
|
|
Good catch, thank you. It turns out that @table was empty because I used a database where the sys.master_files table was empty; therefore, no rows for the cte...
Live and learn
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Today @ 12:43 AM
Points: 584,
Visits: 1,574
|
|
benkoskysa (3/3/2010) ... I used a database where the sys.master_files table was empty...
Well, it can't be empty. At the very least you can expect 8 rows from a brand-spankin' new install, 2 rows for each of master, tempdb, msdb and model. It's likely you don't have the right permissions to this view.
Although, this suggests 2 things: 1) that there is now another reason that people who get a QotD wrong can claim it is invalid - coz the required permissions weren't specified; and 2) that many cut-n-pasters will get the correct answer for the wrong reason.
S.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Friday, June 07, 2013 2:42 PM
Points: 1,662,
Visits: 1,710
|
|
Fal (3/3/2010)
benkoskysa (3/3/2010) ... I used a database where the sys.master_files table was empty...Well, it can't be empty. At the very least you can expect 8 rows from a brand-spankin' new install, 2 rows for each of master, tempdb, msdb and model. It's likely you don't have the right permissions to this view. Although, this suggests 2 things: 1) that there is now another reason that people who get a QotD wrong can claim it is invalid - coz the required permissions weren't specified; and 2) that many cut-n-pasters will get the correct answer for the wrong reason. S. I just should have opted to use a different view to populate the table with 10 records. I chose the sys.master_files for 3 reasons:
1. It has 2 rows for each of the visible system databases (no rows are visible for resource), making it 8 in total 2. Usually we have at least one non-system database (if we have a job ), which adds 2 more records, making it at least 10 in total, which satisfies the test requirement to have 10 records needed for QoD 3. The total number of records is still pretty small so the cte part is not heavy.
I guess the better choice would be to opt for something not heavy but less restrictive, for example
select top 10 row_number() over (order by table_name) record_number from information_schema.tables for the cte part. Thank you for pointing out the flaws in my question. I will try to be more accurate next time.
Oleg
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 5:31 AM
Points: 2,226,
Visits: 438
|
|
Thanks for your QotD! I answered too quick and didn't think of the difference between Len and DATALENGT().
/Håkan Winther MCITP:Database Developer 2008
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 2:43 PM
Points: 10,990,
Visits: 10,576
|
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 1:43 PM
Points: 7,182,
Visits: 7,280
|
|
Paul White NZ (3/30/2010) Not my lucky day. That sounds as if you got it wrong. I can't resist asking which error did you make: a) 11 is an even number; or b) datalength is the same as len
?
Tom Is minic a gheibheann béal oscailte dorn dúnta. Is minig a cheapas beul fosgailte dòrn dùinte.
http://es.linkedin.com/in/tomthomsonsoftware
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 2:43 PM
Points: 10,990,
Visits: 10,576
|
|
Tom.Thomson (3/31/2010)
Paul White NZ (3/30/2010) Not my lucky day.That sounds as if you got it wrong. I can't resist asking which error did you make: a) 11 is an even number; or b) datalength is the same as len  ? Neither really - I just looked at it quickly, decided the answer was probably 'one', and went for it.
Paul White SQL Server MVP SQLblog.com @SQL_Kiwi
|
|
|
|