Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Substr Mid Trim etc in sql 7 queries?? - Urgent!

Thread Tools
 
Search this Thread
 
Old 30 July 2002, 03:58 PM
  #1  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

I want to do

select *
from [blah], [blah1]
where blah.x = Mid(Blah1,3)

so it would match all of fieldx to fieldy , but ignoring the first three chars in fieldy..

Make sense??

David
Old 30 July 2002, 04:01 PM
  #2  
suba
Scooby Regular
 
suba's Avatar
 
Join Date: Mar 2000
Posts: 2,462
Likes: 0
Received 0 Likes on 0 Posts
Post

hmmm... no.

far too technical for me.
Old 30 July 2002, 04:53 PM
  #3  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

You can do it using an inner join which is most efficient as it'll use SQL's join strategy for query execution which should optimise more...

SELECT Table1.*, table2.* from table1 INNER JOIN table2 on mid([table1].[a],4) = mid([table2].[a],4)


Or just plain ol' select:
SELECT Table1.id, Table2.id
FROM Table1, Table2
WHERE (((Mid([table2].[a],4))=Mid([table1].[a],4)));

Old 31 July 2002, 12:54 AM
  #4  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

MID is not a recognised database function or summit similar...

Ill give you a ring tomorrow.

David
Old 31 July 2002, 09:03 AM
  #5  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

aah poo, it just worked for me prototyping in access. Give me a mo.
Old 31 July 2002, 09:07 AM
  #6  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

Microsoft SQL Server supports the SQL 99 substring function...

SUBSTRING(extraction_string [FROM starting_position] [FOR length])

Try that.
Old 31 July 2002, 09:08 AM
  #7  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

extraction_string can be the column name, too.
Old 31 July 2002, 09:22 AM
  #8  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

So should this not work??

as it doesnt...

CREATE VIEW dbo.Test
AS
SELECT Computer_System_DATA.MachineID,
Computer_System_DATA.InstanceKey,
Computer_System_DATA.RevisionID,
Computer_System_DATA.AgentID,
Computer_System_DATA.TimeKey,
Computer_System_DATA.CurrentTimeZone0,
Computer_System_DATA.Description0,
Computer_System_DATA.Domain0,
Computer_System_DATA.Model0,
Computer_System_DATA.Name0,
Computer_System_DATA.Roles0,
Computer_System_DATA.Status0,
Computer_System_DATA.UserName0,
Computer_System_DATA.Manufacturer00,
Computer_System_DATA.SystemType00, PCDetails.TagNo,
PCDetails.Department, PCDetails.Floor, PCDetails.House,
PCDetails.Opsys, PCDetails.Make, PCDetails.Processor,
PCDetails.HDSize, PCDetails.Memory, PCDetails.EquipType,
PCDetails.Model, PCDetails.SerialNumber,
PCDetails.TCPIPAddress, PCDetails.NetworkCard,
PCDetails.Comments, PCDetails.PurchaceDate,
PCDetails.DockingStation, PCDetails.LaptopUser,
PCDetails.LaptopManager
FROM Computer_System_DATA INNER JOIN
PCDetails ON
Computer_System_DATA.Name0 = SubString(PCDetails.TagNo,3,Len(PCdetails.TagNo))


Syntax runs ok but no data returned.

Its too early...

David
Old 31 July 2002, 10:29 AM
  #9  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

David,

you're starting from position *4* aren't you? Cant' recall if this is zero indexed or not, but try that. Or first try selecting the substring and take it from there.
Old 31 July 2002, 11:37 AM
  #10  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

finally this works...

CREATE VIEW dbo.Test
AS
SELECT Computer_System_DATA.MachineID,
Computer_System_DATA.InstanceKey,
Computer_System_DATA.RevisionID,
Computer_System_DATA.AgentID,
Computer_System_DATA.TimeKey,
Computer_System_DATA.CurrentTimeZone0,
Computer_System_DATA.Description0,
Computer_System_DATA.Domain0,
Computer_System_DATA.Model0,
Computer_System_DATA.Name0,
Computer_System_DATA.Roles0,
Computer_System_DATA.Status0,
Computer_System_DATA.UserName0,
Computer_System_DATA.Manufacturer00,
Computer_System_DATA.SystemType00, PCDetails.TagNo,
PCDetails.Department, PCDetails.Floor, PCDetails.House,
PCDetails.Opsys, PCDetails.Make, PCDetails.Processor,
PCDetails.HDSize, PCDetails.Memory, PCDetails.EquipType,
PCDetails.Model, PCDetails.SerialNumber,
PCDetails.TCPIPAddress, PCDetails.NetworkCard,
PCDetails.Comments, PCDetails.PurchaceDate,
PCDetails.DockingStation, PCDetails.LaptopUser,
PCDetails.LaptopManager
FROM Computer_System_DATA INNER JOIN
PCDetails ON
substring(Computer_System_Data.Name0,4,(len(Comput er_System_Data.Name0)-3)) = pcdetails.tagno


just realised though that as one database holds the site location in different field and the other is the three chars that we are removing.... so told them to sort there db out.. by exporting ours... but proved that this can be done... or will when I tell them!

I owe you a pint nick.

David
Old 31 July 2002, 11:51 AM
  #11  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

No worries mate, we got there in the end
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
JimBowen
ICE
5
02 July 2023 01:54 PM
Abx
Subaru
22
09 January 2016 05:42 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
28 December 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
18 November 2015 07:03 AM
Ganz1983
Subaru
5
02 October 2015 09:22 AM



Quick Reply: Substr Mid Trim etc in sql 7 queries?? - Urgent!



All times are GMT +1. The time now is 07:49 AM.