Have a look at this:------------------------------------------------------------' Defines the new querystrSQL = "SELECT Pricebook_Reference.Pricebook_Name_2, MTC_Lookup.Pes, " & _"MTC_Lookup.PROFILE_CLASS_ID, Prices_Table.[Unit Charge] " & _"INTO tblCheckPriceTemp " & _"FROM MTC_Lookup INNER JOIN (Pricebook_Reference INNER JOIN Prices_Table " & _"ON Pricebook_Reference.Pricebook_Reference = Prices_Table.Pricebook_Reference) " & _"ON MTC_Lookup.New_Tariff_Code = Prices_Table.New_Tariff_Code" & _"WHERE (((Pricebook_Reference.Pricebook_Name_2)=[forms].[frmprices]![txtContract]) " & _"AND ((MTC_Lookup.Pes)=[forms].[frmprices]![txtPES]) " & _"AND ((MTC_Lookup.PROFILE_CLASS_ID)=[forms].[frmprices]![txtProfile]) " & _"AND ((Prices_Table.[Unit Charge])=" & oldprice(repeat) & "));"
' puts the new sql into the old queryDim cat As New ADOX.CatalogDim cmd As ADODB.CommandDim dbsDim rst
cat.ActiveConnection = CurrentProject.ConnectionSet cmd = cat.Views("qryCheckPrices").Commandcmd.CommandText = strSQLSet cat.Views("qryCheckPrices").Command = cmdSet cat = Nothing
-------------------------------------------------------------------
See? All it's supposed to do is put the SQL code into the qryCheckPrices query. Nice and easy. But no. It comes up with the error "Item cannot be found in the collection corresponding to the requested name or ordinal", and when I try and debug it highlights this line:
Set cmd = cat.Views("qryCheckPrices").Command
which I don't understand at all.
Anyone have ANY idea what I've done wrong? I know this is what IS departments are for but they're very very busy people and i'd rather not disturb their manic rushing.
― Johnney B (Johnney B), Tuesday, 22 June 2004 08:17 (twenty-two years ago)
― mark grout (mark grout), Tuesday, 22 June 2004 08:32 (twenty-two years ago)
(later . . . . . )
No, exactly the same. Besides, it would have trouble with the line AFTER if it was the SQL that was iffy, surely?
I dunno.
― Johnney B (Johnney B), Tuesday, 22 June 2004 08:40 (twenty-two years ago)
― mark grout (mark grout), Tuesday, 22 June 2004 08:46 (twenty-two years ago)
― Johnney B (Johnney B), Tuesday, 22 June 2004 08:49 (twenty-two years ago)
I have done some VB, but all I can say is to delete the 'command' part and see what the suggestion box gives you etc..
― mark grout (mark grout), Tuesday, 22 June 2004 09:04 (twenty-two years ago)
― Sam (chirombo), Tuesday, 22 June 2004 09:09 (twenty-two years ago)
Uh, Sam . . . . and what does that involve? Sorry, you're gonna have to spell it out to me - I'm not as hot as I'd like on this kinda thing.
― Johnney B (Johnney B), Tuesday, 22 June 2004 09:26 (twenty-two years ago)
― Sam (chirombo), Tuesday, 22 June 2004 09:35 (twenty-two years ago)
― Sam (chirombo), Tuesday, 22 June 2004 09:37 (twenty-two years ago)
Yeah, mine too.
― mark grout (mark grout), Tuesday, 22 June 2004 09:40 (twenty-two years ago)
― VengaDan Perry (Dan Perry), Tuesday, 22 June 2004 10:33 (twenty-two years ago)
but if i change "select *" to "delete" SqlServer complains incorrect syntax near t1. can anyone help? i'm sure there's a better, more efficient way to eliminate dupe rows, i'm not a sql programmer and i'd appreciate any help.
― W i l l (common_person), Friday, 8 July 2005 15:50 (twenty years ago)
Create a SELECT that gets all the data with the duplicates removed. Then create a new table with the same structure as this one and use INSERT INTO newtable SELECT ... to populate it. Then rename (and eventually delete) the original table and move the new table into its place.
(note I don't know anything about SQL Server specifically)
― grraham (noodles is a cunt), Friday, 8 July 2005 15:59 (twenty years ago)
I'm a bit rusty, but if the tables aren't huge, (this may not be the most efficient way but) this should work:
delete from CorrelationsFinalTest where CorrelationsFinalTest.(keyfield) inselect ( keyfield FROM CorrelationsFinalTest t1WHERE EXISTS(SELECT SymbolAFROM CorrelationsFinalTest t2WHERE t2.SymbolA = t1.SymbolA AND t2.SymbolB = t1.SymbolB))
I would normally suggest creating a temporary table to hold the delete criteria (i.e. the nested select where exists stuff) and then delete where table 1 mmatches the temp table. Seems safer to me, but as I said, I'm rusty.
(xpost ..)
― geyser muffler and a quarter (Dave225), Friday, 8 July 2005 16:04 (twenty years ago)
xpost the table has 3.5 million lines :\
― W i l l (common_person), Friday, 8 July 2005 16:06 (twenty years ago)
― geyser muffler and a quarter (Dave225), Friday, 8 July 2005 16:12 (twenty years ago)
SELECT t1.keyfield FROM CorrelationsFinalTest t1, CorrelationsFinalTest t2 WHERE t1.SymbolA = t2.SymbolA AND t1.SymbolB = t2.SymbolB AND t1.keyfield != t2.keyfield
― Forest Pines (ForestPines), Friday, 8 July 2005 16:12 (twenty years ago)
dave225, your suggestion gives me "Error in list of values in IN clause." i wonder if this is some SqlServer bullshit. i found a page that gives three solutions for eliminating dupes using oracle's variety of sql but they generate syntax errors when i try 'em in SqlServer.
― W i l l (common_person), Friday, 8 July 2005 16:22 (twenty years ago)
But, yeah, it might be better to just create a view containing the IDs of the rows you need to delete, and then reference that view in the DELETE.
― David R. (popshots75`), Friday, 8 July 2005 16:27 (twenty years ago)
Anyone know how to convert a binary value that's contained in a varchar variable to a binary variable? I've written a procedure that takes info from sysprocesses, makes it more user friendly and can be viewed from the intranet, and I want to convert the job_id to job_name (using msdb..sysjobs).
The string looks like this:
'SQLAgent - TSQL JobStep (Job 0x57926A9F88B2D7468BB07BDF51E51C63 : Step 18)'
So I used substring to get it down to '0x57926A9F88B2D7468BB07BDF51E51C63' but if I convert that to binary it comes out as 0x30783537393236413946383842324437! Any idea how to convert a string directly to binary as it is?
I have a work-around involving dynamic SQL and a cursor but it would be better if I could just use a CAST/CONVERT statement and do it in one go.
― Colonel Poo (Colonel Poo), Wednesday, 30 August 2006 12:50 (nineteen years ago)
Okay, so I've got a list of site references and dates.
site_no date 123456 2000-01-04 123456 2000-01-08 123456 2000-01-09 123456 2000-01-10 456789 2001-05-18
I want to turn these into a series of start and end date ranges, like this.
Site_No startdate end date 123456 2000-01-04 2000-01-05 123456 2000-01-08 2000-01-11 456789 2001-05-18 2001-05-19
Anyone got any ideas how I could do this in SQL? I'd rather do it without looping if at all possible.
― The Wayward Johnny B, Friday, 4 January 2008 14:34 (eighteen years ago)
What do the dates mean/relate to?
― Mark G, Friday, 4 January 2008 14:36 (eighteen years ago)
They're just arbitrary dates, these don't actually relate to anything! In real life I want to use this principle to work out where there are gaps in billing - so, in this example, site 123456 needs to be billed from the 04/01 to the 05/01 and 08/01 to 11/01.
― The Wayward Johnny B, Friday, 4 January 2008 14:40 (eighteen years ago)
You have dates 04, 08, 09, 10th for 12345
How would that specific example relate to ranges?
― Mark G, Friday, 4 January 2008 14:43 (eighteen years ago)
For site 123456, I want two records, one saying 04/01 - 05/01, and one saying 08/01 - 11/01. Start and end dates, if you like.
― The Wayward Johnny B, Friday, 4 January 2008 14:46 (eighteen years ago)
Oh I see, one for Date 1 to the first day break and then one to the next.
Blimey, I'll have to think.
― Mark G, Friday, 4 January 2008 14:58 (eighteen years ago)
I don't think this would be very easy to do.
That is my useless answer so far.
― Colonel Poo, Friday, 4 January 2008 15:01 (eighteen years ago)
Siteno Date
123456 2000-01-04 123456 2000-01-08 123456 2000-01-09 123456 2000-01-10 456789 2001-05-18
Select SiteNo, DateFrom, DateTo from (Select SiteNo, Date as DateFrom from table left outer join table as table2 on table.siteno = table2.siteno and dateadd(1, table.date) = table2.date where table2.date is null)
inner join
(Select SiteNo, Date as DateFrom from table left outer join table as table2 where table.siteno = table2.siteno and dateadd(1, tabale.date) = table2.date where table2.date is null)
etc, I dunno. Something like that.
― Mark G, Friday, 4 January 2008 15:06 (eighteen years ago)
The first record is fairly easy, I'm getting records that don't have the corresponding next day record.
The second one is harder, as you want 08 rather than 10.
I guess a pre-pass type view, then a "min" function from linking that view to the original table.
Hope that helps in your path.
― Mark G, Friday, 4 January 2008 15:08 (eighteen years ago)
I think I see what you're doing. I get the idea . . kinda. I'll have a play with that idea tho. Cheers mate!
(tho if you get any brainwaves, do tell!)
― The Wayward Johnny B, Friday, 4 January 2008 15:15 (eighteen years ago)
SELECT SireRef, DATEADD(dd, 1, DateFrom) AS DateTo FROM (SELECT table1.SireRef, table1.Date AS DateFrom FROM dbo.tmp_Date AS table1 LEFT OUTER JOIN dbo.tmp_Date AS table2 ON table1.SireRef = table2.SireRef AND DATEADD(dd, 1, table1.Date) = table2.Date WHERE (table2.Date IS NULL)) AS derivedtbl_1
That one gives you, one per break, the site code and the break date.
― Mark G, Friday, 4 January 2008 15:52 (eighteen years ago)
So, relink your orig table to that, select where origtabledate < breakdate, then :
Select SiteRef, min(origtable.date) as DateFrom, DateTo from (blahdiblah) Group by SiteRef, DateTo
Bob's yer.
― Mark G, Friday, 4 January 2008 15:54 (eighteen years ago)
(change that "select where orig...." to "inner join" etc, you know.
― Mark G, Friday, 4 January 2008 15:55 (eighteen years ago)
RIGHT! HERE IS THE ANSWER!!!
SELECT SireRef, MIN(DateFrom) AS DateFrom, DateTo FROM (SELECT dbo.tmp_Date.SireRef, dbo.tmp_Date.Date AS DateFrom, MIN(eee.DateTo) AS DateTo FROM dbo.tmp_Date INNER JOIN (SELECT SireRef, MIN(DATEADD(dd, 1, DateFrom)) AS DateTo FROM (SELECT table1.SireRef, table1.Date AS DateFrom FROM dbo.tmp_Date AS table1 LEFT OUTER JOIN dbo.tmp_Date AS table2 ON table1.SireRef = table2.SireRef AND DATEADD(dd, 1, table1.Date) = table2.Date WHERE (table2.Date IS NULL)) AS derivedtbl_1 GROUP BY SireRef, DateFrom) AS eee ON eee.SireRef = dbo.tmp_Date.SireRef AND dbo.tmp_Date.Date < eee.DateTo GROUP BY dbo.tmp_Date.Date, dbo.tmp_Date.SireRef) AS yeah GROUP BY SireRef, DateTo
I thangyew!
― Mark G, Friday, 4 January 2008 16:07 (eighteen years ago)
Awesome! Cheers sir, much appreciated.
http://www.linksoflondon.com/dynamic/eshop/product_images/thumbnail_cache/360x360/607-thumbprint-star-gold-charm-image-1.jpg
― The Wayward Johnny B, Friday, 4 January 2008 16:12 (eighteen years ago)