|
I think I understand.
Why can't you do your select count(*) to find the # of rows and then do a SELECT TOP [somerandomnumber] to get what you want. Then all you have to do is MoveLast.
|
|
|
|
|
Yes, but even so I still need to do two queries (one to get the count, the other to get my data).
I will try using SELECT TOP and see if it improves the speed.
Thanks
|
|
|
|
|
Hi,
I have a table consisting of an ID, a Date and a StatusCode. Basically it holds a log of when the status of things ('Defects') identified by the ID changed. (The ID is NOT unique in this table).
I am trying to develop an SQL statement that will return the ID and Date for records that have most recently been changed to a certain status. I am using MS Access.
The Query below will return the date that each Defect's status was last changed:
SELECT DefectNumber, Max(DateTime)
FROM MAIN_Status
GROUP BY DefectNumber
I want to be able to discard records from the results of this that are not currently "issued". NOTE: Using a WHERE StatusCode = "ISS" clause does not do what is required - it will give me the most recent date that each Defect has been issued. After a defect has been issued it can then be changed to completed and thus is no longer relevant.
I hope this makes sense...
Any suggestions at all would be great.
Thanks,
Alex
|
|
|
|
|
If I understand what you are asking, I think what you need to do is have a WHERE clause with an IN statement
SELECT DefectNumber, Max(DateTime)
FROM MAIN_Status
WHERE ID not IN (SELECT ID FROM MAIN_Status where sts = 'completed)
GROUP BY DefectNumber
|
|
|
|
|
Would this not just retrieve the Date for when each defect was last issued?
What I require is a list of defects for which the last action was to issue them, and i require the Date at which this took place.
I imagine this is hard to understand without a more verbose description of the problem. Perhaps explaining an analogous situation could help:
A table of employee details as follows:
DepartmentCode Name Salary
1 Alex 40000
1 Kevin 30000
1 Mark 20000
2 Bruce 50000
2 John 60000
3 Michael 70000
Say I want to find the employees in each Department with the highest salary.
I could do:
SELECT DepartmentCode, MAX(Salary)
FROM employees
GROUP BY DepartmentCode
to get a table with DepartmentCode and Salary, but how can i also get the Name of the highest paid person?
The Name is analogous to my StatusCode, if i can get the StatusCode in the results i can use perhaps a HAVING clause to eliminate the ones that are not "ISS".
I hope this makes things clearer
Thanks for your help
~Alex
|
|
|
|
|
Hello
I would like to be able to put files in my Database. But it appears to me( as a rookie) that the size of this files must be very limited. Is this true or am I only looking in the worong places. What type of data type should I use in SQL Server? Image? Binary? When I read the help on these types it seems to me that they only can be very small.
I would like to put files in there that can be up to 1-2 MB. Is this possible?
regards
Henrik
|
|
|
|
|
Typically, you would use binary column types. You can use TEXT type fields IF you encode your file (Base64 is common) before putting it in the DB.
I have put 10-20 meg files in a database, but it really wasn't a good design. I can't comment on your requirements, but for me it has always been better to have a predefined path on a server where files are placed and then just put the path to the file in the database.
|
|
|
|
|
Do you put the file name and file name in differnet columns like
FileName | FileExt | FileData |
1 Document1 xls .......
--------------------------------------
2 Document2 | doc | .......
--------------------------------------
3 Document3 | txt | .......
--------------------------------------
Or is there a better way??
regards
Henrik
|
|
|
|
|
Typically I just use on column and insert the file name like
\\NTSRVR01\DBData\SomeDir\SomeFile.someext
|
|
|
|
|
Thank you very much!!!
It's nice with friendly people when you feel stupid
|
|
|
|
|
I have to write a program based on an SQL Database. I'll write it in
VisualC++ with MFC and ATL... I have to use OLEDB... The program at
its root is composed of many dialogs (one for each table) and many
little search engines (one for each table).
Now the problem is: what model of data connection should I use? Should
I keep open a CSession for the entire time the corresponding dialog is
open? Or perhaps I should open the CSession, read the data, close the
CSession, let the user work on the data that I have loaded and then
reopen the CSession, write the modified row and close the CSession?
The COleDBRecordView class keeps the CSession open...
Another question: If I keep the CSession open, will the row a user is
working on be locked by the SQLServer? Does this depends on the
Isolation Level?
Bye
Max
|
|
|
|
|
Assuume I have the following query:
SELECT * FROM Table1
WHERE
field1 = 4 AND field2 IN (SELECT field FROM Table2)
I assume the SQL server begins a row scan. The question is: "Is the order of the fields in the where clause important?" meaning if current row has field1 != 4 will SQL skip it directly and will not scan the second table? And if I arrange the fields the other way will the second table always be scanned?
Best regards,
Alexandru Savescu
|
|
|
|
|
All depend of your indexs.
For example if you have a index in the table2 that starts with field and other index in the table1 that has field1 and field2 in this order, you will not have scans in your tables, but is very important how is the index, you need to do a good index.
Is not the same that the order in the index will be Field2, Field1 and use Where field2 = 1 and Field1 = 4 you need to evaluate if the index must be field1, field2 or field2, field1 and use that order in the query...
I hope to be clever...;)
Best Regards
Carlos Antollini.
www.wanakostudios.com
Sonork ID 100.10529 cantollini
|
|
|
|
|
Turn SHOWPLAN on and EXECUTE off and you can see what the optimizer does when you run the query both ways.
|
|
|
|
|
Hi,
I have been using ADO for a while now in my current project. Everything seemed to be working well (wishful thinking) until I noticed the following sequence of events:
1. use connection.Execute to run a UPDATE/DELETE etc query against the connected database
2. use connection.OpenSchema to get any schema information back
3. result is the '...the application is using argument that are of the wrong type...' error
Has anyone here experienced this bug, whereby using the Execute method, the connection object seems to get tainted against the OpenSchema method working properly.
I tried to disconnect, then reconnect before doing the OpenSchema call, but the same result.
Please help!
Simon
|
|
|
|
|
Hello,
I seem to have fixed this wierd error, though I don't know why it did!
When I do an action query, I use the connection.Execute method as mentioned. I passed it &vtMissing for the records affected parameter as I saw this in a MSDN example somewhere.
However, and this is the noodler, if I pass NULL for the records affected parameter, the problem goes away! No problem, but I don't see why this would fix it.
Simon
|
|
|
|
|
I'm working a database program using ado.In it ,i use Ado data control with DataGrid control.when i release the program,i have to change the a parameter in ado data control(connection string).for example,The path of old .mdb must to be changed to new path.However ,The ado data control has not change at all!After i used ado.setconnectstring().the program work well.But when the program is released to another pc,the error message appear"cannot initialize data bindings". as if It's from DataGrid. but i don't know how to reset Datagrid or ado parameter.who can help me,please?
|
|
|
|
|
With arrival of yet another Jet 4.0 Service pack (SP6), In 4!!! different exes depending on OS version, is it possible to have installshield to install the latest Jet version along with MDAC in my applications MSI file?
(Solutions using Visual Studio Installer would also be helpful... I don't like Installshield much)
Thanks...
Blade[DMS]
|
|
|
|
|
check in the site of the product...
May be Install Shield, developed a new object for that.....
regards
Carlos Antollini.
www.wanakostudios.com
Sonork ID 100.10529 cantollini
|
|
|
|
|
Yes I've found that...
Thanks...
Blade[DMS]
|
|
|
|
|
Dear Codeproject Users,
I want to make a Win application that uses a database, currently I am using ADO and Visual Studio .NET.
I want the user to be able to create an account on a database hosted remotely on a server in the internet, or if the users already has an account he can login. (This is what happens with programs like Napster).
After when a user logins he can edit his profile in the database (he can update only one record in the database, the record associated with his username).
How I accomplish this, there is a good tutorial out there?
Thx
"Nelle cose del mondo non e' il sapere ma il volere che puo'."
|
|
|
|
|
I want to define a custom datatype in SQL. I need it to be a structure that contains multiple fields. There is n't a struct datatype in SQL. How should I do this? Thanks.
Steve
Not all who wander are lost...
|
|
|
|
|
What database are you working with?
SQL Server, Access, DB2 do not support what you are asking for exactly. SQL Server supports custom data types, but they are just simple types with pre-defined defaults and rules.
Typically when working with a DB, you just flatten your strucutre into columns and deal with it like that.
Object oriented databases and XML based databases do support the concept of a struct (or entity), but this only applies if you are working with one of these forms of DB.
|
|
|
|
|
I am working with MS SQL Server 2000.
I am developing a large app that has app based security. I was looking for a way to embed this info in the database. If worst comes to worst I will just have the same fields at the top of each table.
Steve
Not all who wander are lost...
|
|
|
|
|
I don't know how your tables are layed out, but you might be able to have a single table for this info and have a 1:1 relationship between this table and the others. If you're tables aren't layed out easily, you could have an identity column in your strucutures table and add a column to each of your tables pointing to the identity column on the strucutues table.
Another idea (just a thought, I've never done this) would be to use a blob or if possible a char field for the entire structure. If it can be easily represented as text you could just string it together (comma delimited, etc) and stuff it in a single column.
|
|
|
|