|
I do not think that it is possible to write a single query to achieve what you are trying to do. There could be more than a single set of rows whose sum of qty = 10, how would you handle that?
|
|
|
|
|
So you want to solve a knapsack problem[^] in SQL? You do realize the problem is NP complete?
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|
|
|
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|
|
the link you had given pointed me to Backpack
I think what you mean is Knapsack_problem
I realize the complexity.
But at any given time max rows can b only 50-100,i am getting these rows from Select statement.
Then from these rows i have to get rows whose sums equals to Qty given (input).
So, will you please help me finding an algorithm to solve.
Regards
|
|
|
|
|
The problem is actually known as the subset sum problem as konduc pointed out, with a useful link.
As your number of rows is limited, you should load them all in memory and go for a normal solution, not a database-centric SQL one. Now start studying the keywords and links given to you, and help yourself with Google and/or some books. No one is going to do your job for you.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|
|
Hi all,
How can i convert MSSQL database to MySQL database ?
Thanks in advance.
|
|
|
|
|
I would start by going to Google and typing "convert mssql to mysql". That gives over 2 million hits. At least one of them must be useful.
|
|
|
|
|
The simplest way is to use the 'Generate Scripts' option in MSSQL and create the full script for the database and all its objects (including the data in the tables), then adapt the resulting script to MySQL syntax and run it on the MySQL database.
|
|
|
|
|
Convertion of MSSQL database to MySQL database can mean a lot of things.
Migration of Tables and Data.
Migration of stored proc, triggers etc.
Doing the first one is relatively easy and less labour intensive and can be done in a lot of ways.
One example would be first to generate the create table scripts and edit them to suit MySQL.
Execute these to create the tables in MySQL.
Export the data from MSSQL to MySQL.
Lastly apply the foreign keys.
For each of these steps, there are tools available.
The below mentioned link may help you.
http://kofler.info/english/mssql2mysql/[^]
--
obhijitghosh
|
|
|
|
|
Hi guys,
Here's what I'm trying to accomplish. better said I'm trying to determine the speediest way of doing it.
I need to check if lets say orders exists for a customer and then do some more stuff.
so far the speediest way seems to be something like this:
use [db]
go
Set RowCount 1
go
Select ID from Table where ColName='Value'
go
Set RowCount 0
basically I want the sql server to stop processing as soon as a match is found. As you know, TOP doesn't work that way.
Something like this in C# :
foreach(var item in colection){
if(conditon) return true;
}
I'm no SQL expert. So, sorry if the question seems silly for some of you DB admin guys.
So the question is this:
Is there a faster/better way of achieving this?
[add]
Never mind. Exists()
So caught up in the idea that I totally forgot about it.
[/add]
All the best,
Dan
modified on Thursday, June 9, 2011 5:08 AM
|
|
|
|
|
How about
select c.customer_id
from customer_table c
where exists ( select rowid from orders_table t
where t.customer_id = c.customer_id
)
Should give you a list of customer ids that have orders.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Yeah thanks. I figured it out.
I just wanted the fastest way of seeing if something exists() and then go do the job.
[add]
This is what I wanted:
IF Exists(Select ID from Table1 where ColName='Value')
Insert Into...
I'm laughing my ass out now after the 30 min feverish thinking(about speed) and searching.
It was right in from of me. Doh
[/add]
Thanks anyway.
All the best,
Dan
modified on Wednesday, June 8, 2011 2:44 PM
|
|
|
|
|
MDL=>Moshu wrote: seeing if something exists() and then go do the job
If you're going to do it, just do it, don't check first.
|
|
|
|
|
Generally it's a very good idea. But the thing is this.
I have a production app(scanners and all that) and normally a interface for setting up the lines,projects...
I did not allow them to delete a PN. Now they want that feature.
But in order to not delete any production data I need to check if any production data exists for that PN
and if not, then and only then delete all stuff related to that PN. Else refuse it.
Yeah I know SQL would return an error complaining about FK and stuff but I don't want the user to see that.
So first check and if not exists then delete.
Else show a message to the user that production datas exists for that PN and delete has been aborted.
All the best,
Dan
modified on Thursday, June 9, 2011 5:05 AM
|
|
|
|
|
I have declare a variable in date format in Oracle(toad). for that i insert the value System.DateTime.Now in C#. when i exceute the Procedure it shows the error. ORA-01843: not a valid month.
|
|
|
|
|
this is what I can tell you about such issues:
- if you are using an appropriate field type (date, time, datetime, etc), then the most likely bad value you could have is a NULL value.
- if you are using strings (varchar, whatever) to store date/time information, you are bound to get into trouble with regional settings, languages, etc. Just don't use strings!
If that doesn't help, either Google the error message, you'll get a lot of hits. Or show us more detailed information on your table, your code, and the actual data that fails.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
dd mm yyyy vs mm dd yyyy , anyone?
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
that is what I was hinting at with "regional settings".
it isn't wise to use strings for storing dates, and when (one thinks) one has to, one should use an invariant culture thingy, and not rely on regional settings that could be changed by the user and create havoc overnight.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
|
You're welcome.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|
|
Has someone experience applying clustered index more than on one field?
I think it is wrong action. May be it could work with small database. My observation showed such estimation: same table same number of records. Execution query to select all fields from same table without having clustered index on single column is 8sec (650243). In other case I have apply clustered index on primary and foreign keys. Execution last about 12 sec.; basically it decreased performance. So now is a question: if I can apply non clustered index on couple fields, what is the best practice to apply clustered index. Whether it should be only single field to sort data in a table?
We live in a Newtonian world of Einsteinian physics ruled by Frankenstein logic
|
|
|
|
|
By definition, there can only ever be a single clustered index on a table - it is the clustered index that sets the physical order of records. Usually, the clustered index would be on a single field, and generally that will be a key field that auto-numbers. The performance hit for clustered indices is more related to inserts and updates on your data, as if you insert/update a record that is towards the start of the index, and make it fall towards the end, nearly the whole table is physically reordered on the disk to accomodate this.
|
|
|
|
|
Thank you. You confirmed my thoughts.
We live in a Newtonian world of Einsteinian physics ruled by Frankenstein logic
|
|
|
|
|
I have created one Ssis pkg in my local DB.I am connecting to the the remote server by using C# code in this Ssis pkg.But some cases(machines) it's giving error(user-component failure).So i need to conn remote DB and i have to execute Stored procedure in that DB.
Can anyone give me suggestions to conn remote DB from local DB(machine) or Anyone known about this error?
|
|
|
|