![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
pbd22 wrote: select coalesce (tab1.postalAddress, tab2.name, tab3.postaladdress, tab4.postaladdress) id , tab1.bdayday , tab1.bdaymonth , tab1.bdayyear , tab1.sex , tab1.zipCode , tab1.siteId , tab1.userID , tab2.photolocation , tab2.photoname , tab2.photodefault , tab2.nophoto , tab3.headline , tab3.aboutme , tab4.signindate from Why the hell doesn't anyone format their queries for readability? order by CASE WHEN userID=67 THEN 1 WHEN userID=103 THEN 2 WHEN userID=102 THEN 3 WHEN userID=81 THEN 4 WHEN userID=94 THEN 5 WHEN userID=87 THEN 6 WHEN userID=104 THEN 7 WHEN userID=82 THEN 8 WHEN userID=54 THEN 9 WHEN userID=64 THEN 10 WHEN userID=63 THEN 11 WHEN userID=6 THEN 12 WHEN userID=58 THEN 13 WHEN userID=100 This should be driven by a Users table. Do you really want to mess around with altering the query every time a user is added/removed? |
#12
| |||
| |||
|
|
On Apr 12, 6:50 pm, Ed Murphy <emurph... (AT) socal (DOT) rr.com> wrote: pbd22 wrote: select coalesce (tab1.postalAddress, tab2.name, tab3.postaladdress, tab4.postaladdress) id , tab1.bdayday , tab1.bdaymonth , tab1.bdayyear , tab1.sex , tab1.zipCode , tab1.siteId , tab1.userID , tab2.photolocation , tab2.photoname , tab2.photodefault , tab2.nophoto , tab3.headline , tab3.aboutme , tab4.signindate from Why the hell doesn't anyone format their queries for readability? order by CASE WHEN userID=67 THEN 1 WHEN userID=103 THEN 2 WHEN userID=102 THEN 3 WHEN userID=81 THEN 4 WHEN userID=94 THEN 5 WHEN userID=87 THEN 6 WHEN userID=104 THEN 7 WHEN userID=82 THEN 8 WHEN userID=54 THEN 9 WHEN userID=64 THEN 10 WHEN userID=63 THEN 11 WHEN userID=6 THEN 12 WHEN userID=58 THEN 13 WHEN userID=100 This should be driven by a Users table. Do you really want to mess around with altering the query every time a user is added/removed? good point Ed. I didn't think of that. I'll obviously have to do that - yet another thing on the "to-do list". thanks... |
#13
| ||||
| ||||
|
|
I have pasted the code below (sorry if i offend anybody about formatting. I am not sure how to format code here... suggestions?). When I use Query Analyzer and step through the code in "debug" mode, the compiler jumps to the following line: ---------------------------- SET ROWCOUNT 0 ---------------------------- and throws this error: --------------------------------------------------------------------------------------------- CurrentPage TotalPages TotalRows ----------- ----------- ----------- 0 0 0 Server: Msg 507, Level 16, State 2, Procedure sp_SearchRowCount, Line 60 [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid argument for SET ROWCOUNT. Must be a non-null non-negative integer. @RETURN_VALUE = -6 --------------------------------------------------------------------------------------------- Could somebody tell me what about the logic in my code is causing this failure (I know that the value is null and that that is causing the error). I have a feeling it might have to do with the following lines of code that I have commented out in the WHERE clause (but, I am not sure what it is doing or how to add the logic to my own code): |
|
SET ROWCOUNT @lbound |
|
SET ROWCOUNT @perPage |
|
SELECT CurrentPage = @pagenum, TotalPages = @pages, TotalRows = @rows |
#14
| |||
| |||
|
|
On 18 Apr 2007 06:12:44 -0700, pbd22 wrote: I have pasted the code below (sorry if i offend anybody about formatting. I am not sure how to format code here... suggestions?). When I use Query Analyzer and step through the code in "debug" mode, the compiler jumps to the following line: ---------------------------- SET ROWCOUNT 0 ---------------------------- and throws this error: --------------------------------------------------------------------------------------------- CurrentPage TotalPages TotalRows ----------- ----------- ----------- 0 0 0 Server: Msg 507, Level 16, State 2, Procedure sp_SearchRowCount, Line 60 [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid argument for SET ROWCOUNT. Must be a non-null non-negative integer. @RETURN_VALUE = -6 --------------------------------------------------------------------------------------------- Could somebody tell me what about the logic in my code is causing this failure (I know that the value is null and that that is causing the error). I have a feeling it might have to do with the following lines of code that I have commented out in the WHERE clause (but, I am not sure what it is doing or how to add the logic to my own code): Hi pbd22, Since those commented lines are *AFTER* the place where the error occurs (the debugger jumps to the incorrect line; the only line that can cause this error is either this one: SET ROWCOUNT @lbound or this one: SET ROWCOUNT @perPage I assume that it's the first, and that it's cause by some unexpected things going on in the calculations neede to compute @lbound. You already have added a great statement to aid in debugging; I'm gonna ask you to add a bit more to it - so please change this: SELECT CurrentPage = @pagenum, TotalPages = @pages, TotalRows = @rows to this: SELECT CurrentPage = @pagenum, PageSize = @perpage, TotalPages = @pages, TotalRows = @rows, UpperBoundary = @ubound, LowerBoundary = @lbound And then rerun the query and post back the results. We'll then have to take it from there. -- Hugo Kornelis, SQL Server MVP My SQL Server blog:http://sqlblog.com/blogs/hugo_kornelis |
#15
| |||
| |||
|
|
Thanks for your reply. I have made the changes you suggested and got the following output: CurrentPage PageSize TotalPages TotalRows UpperBoundary LowerBoundary -----------........ ----------- ...... ----------- ..... ----------- ........... ------------- .......------------- 0 ........ 10 .......... 0 ..... 0 ............ 0 ....... -9 Server: Msg 507, Level 16, State 2, Procedure sp_PeopleSearch, Line 63 [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid argument for SET ROWCOUNT. Must be a non-null non-negative integer. |
#16
| |||
| |||
|
|
On 18 Apr 2007 09:10:16 -0700, pbd22 wrote: (snip) Thanks for your reply. I have made the changes you suggested and got the following output: CurrentPage PageSize TotalPages TotalRows UpperBoundary LowerBoundary -----------........ ----------- ...... ----------- ..... ----------- ........... ------------- .......------------- 0 ........ 10 .......... 0 ..... 0 ............ 0 ....... -9 Server: Msg 507, Level 16, State 2, Procedure sp_PeopleSearch, Line 63 [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid argument for SET ROWCOUNT. Must be a non-null non-negative integer. Hi pbd22, Thanks. This makes a lot clear. Obviously, there are no rows returned by your query. Or to be more precies - by the first copy of your query. You will have noted that you have multiple copies of the same query in the procedure; the first copy uses "SELECT @rows = COUNT(*), @pages = COUNT(*) / @perpage" to find the total number of rows in the query. Since @rows is only set here, and it is shown to be 0 in the results above, the query obviously returns no rows. That means that either the query you want to run in a paged mode does in fact not return any rows, or that you made a mistake when making the extra copies of this query. After this row-counting, some calculations are done: (1) IF @rows % @perpage != 0 SET @pages = @pages + 1 (2) IF @pagenum < 1 SET @pagenum = 1 (3) IF @pagenum > @pages SET @pagenum = @pages (4) SET @ubound = @perpage * @pagenum (5) SET @lbound = @ubound - (@perpage - 1) Line 1: The value of @perpage is rounded down in the query; this line corrects that to rounding up. I'd have done that a little differently, but that's mostly a matter of taste, and it works. Line 2: In case someone passed a page number of zero or less to the procedure, set it to 1. This is to prevent erroneous results. Line 3: Another sanity check - if the page number passed to the proc exceeds the actual number of pages, set it to the highest actual page number. In this case, with 0 rows, this sets the page number to 0; exactly the value that line 2 attempts to prevent!! This is the source of the error you received. Lines 4 and 5: Based on the page number, calculate the number of the first and the last row to display. For page number 1, these numbers would have been 1 and 10. For page number 0, the calculation yields -9 and 0. As a result, the proc later tries to set a negative ROWCOUNT. I _think_ that you can easily fix this by swapping lines 2 and 3. I have not checked every bit of the proc, but I suggest that you simply try it and see what happens. If this results in (different) problems, you'll have to explicitly add code to handle the possibility of an empty result set. I have already sent a mail to the author of the aspfaq article I refered you to earlier, asking him to correct this page. -- Hugo Kornelis, SQL Server MVP My SQL Server blog:http://sqlblog.com/blogs/hugo_kornelis |
#17
| |||
| |||
|
|
MY final question is - why don't I get any data returned with the query? Shouldn't I be seeing results with the column headers? Or, is this just to show that the query works in debug mode? Sorry - still trying to learn my way around stored procedures. |
#18
| |||
| |||
|
|
On 18 Apr 2007 11:57:53 -0700, pbd22 wrote: (snip) MY final question is - why don't I get any data returned with the query? Shouldn't I be seeing results with the column headers? Or, is this just to show that the query works in debug mode? Sorry - still trying to learn my way around stored procedures. Hi Peter, You're probably going to hate me for this, but my best guess is that your tables simply don't contain any data that matches the criteria in the trigger. I already hinted at this in my previous reply (though I left a back door open for the possibilty that one of the queries contained a copy/paste error). -- Hugo Kornelis, SQL Server MVP My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis |
![]() |
| Thread Tools | |
| Display Modes | |
| |