|
Umm... Wow!
There are a number of things that are wrong with this before we even get to solving the problem you posted about.
1. Why are you creating a stored procedure like this?
2. Your code is vulnerable to a SQL Injection attack.
3. The use of SET ROWCOUNT should be discouraged because it will affect other queries that happen to be running at the same time. Use SELECT TOP n instead (where n is the number of rows you want)
If you are running SQL Server 2005 the answer is quite simple as there is some new functionality built in to address this problem. If you are running SQL Server 2000 then it is workable, but the query will be more complex. Which version of SQL Server are you using?
|
|
|
|
|
I'm using SQL Server 2000, and the code wont actually be building the query in the long run, this is just basically a proof of concept and is like this for the time being so that I can play with it in a designer I coded...SET ROWCOUNT is set back to 0 at the end to restore it for latter query's. An explanation of why I'm using SET ROWCOUNT can be found here:
http://www.4guysfromrolla.com/webtech/042606-1.shtml[^]
It is a fairly efficient way of doing this...
I'm only trying to find a way to incorporate an order by into this...
--
"Keyboard not found. Press < F1 > to RESUME. "
Source unknown (appears in many common BIOSes as a real error message)
|
|
|
|
|
Polymorpher wrote: SET ROWCOUNT is set back to 0 at the end to restore it for latter query's. An explanation of why I'm using SET ROWCOUNT can be found here:
http://www.4guysfromrolla.com/webtech/042606-1.shtml[^]
It is a fairly efficient way of doing this...
Maybe, but it is also a fairly dangerous thing to do. SET ROWCOUNT will affect other queries running at the same time. If you are never going to have other users then this is fine. But in that case why are you using something like SQL Server.
As for incorportating an order. Use subquerys - If you expect to be paging through lots of data then you may wish to use a temp table for the innermost SELECT. Also, remember to only use the columns you actually need, this will help the performance of the query rather than the demonstration SELECT * I've used here.
First lets, say you want rows 76 to 100 (25 rows in total). Get the first 100 rows
SELECT TOP 100 *
FROM MyTable
ORDER BY OrderColumn
Then Reverse the order of the result set getting only 25 rows
SELECT TOP 25 *
FROM (SELECT TOP 100 *
FROM MyTable
ORDER BY OrderColumn)
ORDER BY OrderColumn DESC
Finally, flip the order back again:
SELECT *
FROM (SELECT TOP 25 *
FROM (SELECT TOP 100 *
FROM MyTable
ORDER BY OrderColumn)
ORDER BY OrderColumn DESC)
ORDER BY OrderColumn
|
|
|
|
|
|
|
Given that you didn't say which version of SQL Server in your original post...
|
|
|
|
|
Hello,
I have table1 with fields id, date, usernamename. I can get the count of records created by user(s) for certaing date range, but if user 'A' has not inserted any records it is missing from result. What I want to achieve is to be able to display the username, with count=0. I know it should be some sort of self join but I can't manage to get it work.
All suggestions appreciated!
|
|
|
|
|
You can use GROUP BY with the HAVING clause.
SELECT username
FROM your_table
GROUP BY username
HAVING COUNT(*) = 0
|
|
|
|
|
I've tried this also, it does not return records in my case.
|
|
|
|
|
You're right! I've should've seen that. It can't possibly work...
Will something like this work?
SELECT y1.Username
FROM your_table y1
LEFT JOIN your_table y2
ON y1.Username = y2.Username
WHERE y2.date BETWEEN start AND end
GROUP BY y1.Username
HAVING COUNT(y2.Username) = 0
The table alias y1 represent all usernames and y2 represent only the records within the requested range.
|
|
|
|
|
i would like to know the differnce between the fixed server roles and data base roles in sql server 2005 . and in my application i use three types of users called admin,mgr,operator and i want to give privileges to each of them to accss the db and the application.so using the roles how can i do this ,Specially apply privileges to each user...
|
|
|
|
|
|
I am not understanding the permission problem I am having and what the Schema object is for.
My Database has Stored procedures owned by a user, let say corp. If I look at the database there is a Schema also called corp owned by corp.
corp has all roles except db_DenyDatareader and db_DenyDatawriter and is not aliased to dbo.
Now it has been my understanding that since the user corp owns the Stored procedure it should have execute rights to it.
The problem is when my application opens and tries to execute a stored procedure I get denied for lack of Execute permission. If I log into the database using enterprise manager (2005 version) with the corp login I can get into the database but I can not see any of the Stored procedures that the corp user owns.
I can not figure out this issue any ideas are greatly appreciated.
Thanks
|
|
|
|
|
i cant run my program, there's an error:
Type 'BOOK_Locator.Dataset1' is not declared
in codes:
Friend WithEvents DataSet11 As BOOK_LOCATOR.DataSet1
i have connected my database in connection wizard properly but why there's an error in it? how can i fix?
|
|
|
|
|
|
As others have said, don't cross post. That is very rude.
Rharzkie wrote: Type 'BOOK_Locator.Dataset1' is not declared
That pretty much tells you the problem. Is the error occurring within the scope of where you have it declared?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
i used the data adapter connection wizard, but when i chose my database, there's an error...
it says:
IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
what is the meaning of that? how will i fix it?? i really need to make a connection wizard for my project...
|
|
|
|
|
|
Ok, this will be very hard to explain since I haven't personnally seen this myself.
I have a web site programmed with an Access database as the backend database. All has been working for over 3 years. Recently the employees are saying they are changing things in the database, both through the table itself, and through forms in the database(horrible I know, but my employer will not pay me to write all that code). But they say that SOMETIMES, it doesn't save the changes, which contradicts both computers with the sometimes, and Access since it writes constantly.
Has anyone seen this happen before? Know of a fix? Anything?
I have checked to see that there is enought disk space, and that they have sufficient privilages. ANY help at all, leads, ideas, absolutly anything, will be greatly appriciated.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Is the MDB file in the folder which is writeable by the process?
|
|
|
|
|
Yes, my code all works as far as C#. Is is when the users are actually in the database using its forms and tables.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Expert Coming wrote: through forms in the database(horrible I know, but my employer will not pay me to write all that code)
I can relate to that from a few experiences out there.
Expert Coming wrote: say that SOMETIMES, it doesn't save the changes, which contradicts both computers with the sometimes, and Access since it writes constantly.
Is there any kind of record-level locking going on? Access can let you turn such a thing on and off...
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Not sure, it would be the default which I am sure is locked. Do you know what the default is?
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
I think the default is set to No Locking . Or your problem could be something completely different, though.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
hello all,
i am working on a application to get the last updated date for a table. the date is already in the table in the UPDATE_TIMESTAMP column. Now the following code is not getting the result for me. can anyone help? I am getting an insufficient priviliges error
public static string GetLastUpdateTime()
{
StringBuilder sb = new StringBuilder();
sb.Append("SELECT MAX(updated_timestamp) lastUpadateTime FROM TABLEA");
OracleHelper oracleHelper = new OracleHelper();
string sql = sb.ToString();
object obj = oracleHelper.ExecuteScalar(Utility.GetConnectionKey(),CommandType.Text,sql);
if (obj == DBNull.Value)
{
return "";
}
return ((DateTime)obj).ToString("mm/dd/yyyy");
}
|
|
|
|