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 Jul 30, 2002 | 03:58 PM
  #1  
David_Wallis's Avatar
David_Wallis
Thread Starter
Scooby Regular
 
Joined: Nov 2001
Posts: 15,239
Likes: 1
From: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
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
Reply
Old Jul 30, 2002 | 04:01 PM
  #2  
suba's Avatar
suba
Scooby Regular
 
Joined: Mar 2000
Posts: 2,462
Likes: 0
Post

hmmm... no.

far too technical for me.
Reply
Old Jul 30, 2002 | 04:53 PM
  #3  
chiark's Avatar
chiark
Scooby Regular
 
Joined: Jun 2000
Posts: 13,735
Likes: 0
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)));

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

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

Ill give you a ring tomorrow.

David
Reply
Old Jul 31, 2002 | 09:03 AM
  #5  
chiark's Avatar
chiark
Scooby Regular
 
Joined: Jun 2000
Posts: 13,735
Likes: 0
Post

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

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

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

Try that.
Reply
Old Jul 31, 2002 | 09:08 AM
  #7  
chiark's Avatar
chiark
Scooby Regular
 
Joined: Jun 2000
Posts: 13,735
Likes: 0
Post

extraction_string can be the column name, too.
Reply

Trending Topics

Old Jul 31, 2002 | 09:22 AM
  #8  
David_Wallis's Avatar
David_Wallis
Thread Starter
Scooby Regular
 
Joined: Nov 2001
Posts: 15,239
Likes: 1
From: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
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
Reply
Old Jul 31, 2002 | 10:29 AM
  #9  
chiark's Avatar
chiark
Scooby Regular
 
Joined: Jun 2000
Posts: 13,735
Likes: 0
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.
Reply
Old Jul 31, 2002 | 11:37 AM
  #10  
David_Wallis's Avatar
David_Wallis
Thread Starter
Scooby Regular
 
Joined: Nov 2001
Posts: 15,239
Likes: 1
From: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
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
Reply
Old Jul 31, 2002 | 11:51 AM
  #11  
chiark's Avatar
chiark
Scooby Regular
 
Joined: Jun 2000
Posts: 13,735
Likes: 0
Post

No worries mate, we got there in the end
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
JimBowen
ICE
5
Jul 2, 2023 01:54 PM
Abx
Subaru
22
Jan 9, 2016 05:42 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
Dec 28, 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
Nov 18, 2015 07:03 AM
Ganz1983
Subaru
5
Oct 2, 2015 09:22 AM




All times are GMT +1. The time now is 09:52 AM.