|
So does my test script work for you?
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
select min(PK),Trans.ID from FEE
group by Trans.ID
try this
|
|
|
|
|
Why do you need the WHERE clause? Can't you just do:
select TransId, min(PK) from FEE group by TransId
|
|
|
|
|
You can if you also want the transid (which I suspect is the case), but the OP just wanted the PK
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Hi guys,
I'm struggling with something conceptually that maybe somebody would be able to help me with. I'm writing an application to match vehicles in one database to vehicle in another database. As you can imagine there are difference all over the place so there will be a lot of manual matching to be done but I'm doing my best to cut down on the amount of manual work where possible. The LIKE predicate has definitely been my friend here, but how can I make it work the other way around, i.e. instead of C_Model LIKE '%Fiesta%' I could do with 'Fiesta' LIKE %C_Model%. If you know what I mean?
For instance I can match this:
DB1 DB2
'Fiesta' -> 'Fiesta 1'
-> 'Fiesta 2'
-> 'Fiesta 3'
...but I don't know how to go this way:
DB1 DB2
'306 -97' -> '306'
'306 97-' -> '306'
Cheers,
Chris Chambers.
|
|
|
|
|
You may now get ready to kick yourself....
You have no problem getting DB2 like 'Fietsa%'
what is wrong with getting Db1 like '306%'
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yeah, maybe I should have explained myself better.
Take this statement from the second databases DataSet class:
return (ModelsRow[])this.Models.Select("C_Make = '" + make + "' AND C_Model LIKE '%" + model + "%'");
Is there an expression I can use to try to further enhance this expression to help me retrieve the records where C_Model is like the model passed in? If '306 -97' is passed in and the models table contains '306' rows how can I get to those rows? Like I say, it's fine if I pass in 'Fiesta' and the models table contains 'Fiesta 1', 'Fiesta 2', 'Fiesta 3' etc.
The more I think about this the more I'm beginning to think it's not possible. I just don't see how I can select rows where a certain field matches a substring of a literal string.
|
|
|
|
|
return (ModelsRow[])this.Models.Select("C_Make = '" + make + "' AND C_Model LIKE '%" + model + "%' or C_Model like '306%'");
This answer is too simple I must be missing something in your question.
I use stored procs for 99.9% of my database work and therefore can design the SQL to do exactly what I want in QA/EM. I suggest you do this to get the result you want and then move it to a string if that is where you want to have you SQL. Also look into parameterised queries, you current model is subject to sql injection.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi Mycroft,
Mycroft Holmes wrote: return (ModelsRow[])this.Models.Select("C_Make = '" + make + "' AND C_Model LIKE '%" + model + "%' or C_Model like '306%'");
This won't work because the '306' is what's actually in C_Model; at the point this statement is executed I don't actually know what that is. I just used that '306' string as a typical example.
To be honest, the more I've thought about this the more I've decided it's a stupid thing to do in the context of my application anyway so I've abandoned the idea for now. I'm sorry if I've wasted your time. Many thanks for your help anyway.
Thanks again,
Chris Chambers.
|
|
|
|
|
Not a problem
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm not sure if I understand your question. I think this will do what you want:
select * from Models
where C_Model like '%306 -97%'
or '306 -97' like C_Model + '%'
It won't be the fastest query in the world, but it should do what you want. It will pick out models that have 306 -97 anywhere in the model number, (e.g. '4306 -97') and it will also get all the rows with model numbers '306'. If there are any rows with model number '3' or '30' it will get those too, but that's what you seem to be asking for.
|
|
|
|
|
Hi David, thanks for your input.
I might try that to see if it works in my application, however as you rightly said it's likely to pick up quite a few entries that I don't want so as I said to Mycroft I think I've decided not to go ahead with it. I'll let you know if that works though.
Regards,
Chris Chambers.
|
|
|
|
|
I think Mycroft is right.
And if all else fails, you could still use substrings and go for an exact match of the first N characters.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thanks for your input Luc, much appreciated.
Regards,
Chris Chambers.
|
|
|
|
|
Id Credit Debit CurrentCredit Current Debit
51 21500 0 21500 0
52 0 21500 0 0
89 0 2150 0 2150
93 0 2140 0 4290
128 2140.5 0 0 2149.5
129 2151.5 0 2 0
171 0 1628 0 1626
190 1628 0 2 0
i have column of credit and debit and want to get columns of current credit and current debit
example:
51. credit=21500 and debit=0
i have credit more than debit so this increase credit and decrease debit
then
current credit = 0+21500
52. credit=0 and debit=21500
i have debit more than credit so this decrease credit and increase debit
then current credit =0 and current debit =0
89 credit=0 and debit =2150
i have debit more than credit so this decrease credit and increase debit
then current credit =0 and current debit=0+2150=2150
93 credit=0 and debit =2140
i have debit more than credit so this decrease credit and increase debit
then current credit =0 and current debit=2140+2150= 4290
and so on...
|
|
|
|
|
That's very interesting. Is there a question in there?
|
|
|
|
|
Are you just looking for this?
SELECT SUM(CurrentCredit) - SUM(CurrentDebit) AS FinalBalance FROM myTable
|
|
|
|
|
As interesting as your data is, what is your query?
"My interest is in the future because I'm going to spend the rest of my life there." - Charles F. Kettering
|
|
|
|
|
Hi
I have a table with duplicate rows and distinct id. I have written a select query using distinct and selecting only required fields to avoid duplicates.
Select dictinct(occassion), startdate from table1
Now what i want is to give unique row number to each distict row
For this i tried as below but could not succeed
Declare @num int
set @num =0
select (set @num = @num+1) as num,
dictinct(occassion), startdate from table1
After search in google , i got row_number(). But this i am unable to use as i am using distinct. Can u pls let me know how i can achieve this.
Thanks in advance
Naina
Naina
|
|
|
|
|
What are you going to do with the unique row number? How will it assist you? Where are you using it?
|
|
|
|
|
Hi
Thanks for the reply.
It is very useful for me. As i will use it in my web page (front end) where other functionality related to this unique number is related to.
Please help me to get this.
Regards
Naina
Naina
|
|
|
|
|
Cant you just use ID in the record from table itself?
|
|
|
|
|
hi all,
would like to receive help on how to connect to a magic software database using vb.net.
thank you very much.
|
|
|
|
|
I'll bite, if you can't find something at connectionstrings.com then you need to go back to the vendor. Never heard of it before!
|
|
|
|
|
I came across Magic Software back in the early 90's, I have to say (at the time) it was very inmpressive but too expensive for the company I was employed by at the time. I haven't come across it since, so I assumed like many other companies, it had gone under. Great product, dodgy name
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|