Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Sql Query

Author  Topic 

drpkrupa
Yak Posting Veteran

74 Posts

Posted - 2006-07-28 : 11:49:24
Question regarding sql query.

If I have address field and I want a write query which show me only street no. How can i do that

Ex: 1225 ABC Drive - 1225
1530 14 1/2 ST - 1530

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-07-28 : 11:58:07
How do u know what is street # ?
Is it the #s appear in the address just b4 meeting the first space when checked from left ?
Can there be any other characters in the begining of the address ?
eg. No. 456 Brimley Road
Can there be any other characters as comma etc ?

explain ur data and post some more data & results expected.

Srinika
Go to Top of Page

drpkrupa
Yak Posting Veteran

74 Posts

Posted - 2006-07-28 : 12:09:07
here is the way data store in out table and the my result, which i want out of query.

Address
1225 ABC Drive
1530 14 1/2 ST

I need result as
1225
1530
How can i do that.
I know i can do like this in oracel but sql dont support instring.
SUBSTR(address1,0,INSTR(address1,' ')-1 )
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-07-28 : 12:21:09
drpkrupa,

Can u please read thru my post and answer it. U didn't post any answer or explanation, just the same things asked in ur first post are reposted, in a different format.

But if I do some assumptions, following works:

create table #t (Address varchar (100))

Insert into #t values ('1225 ABC Drive')
Insert into #t values ('1530 14 1/2 ST')

select SUBSTRING(Address,1,charindex(' ',Address)-1) as [Street #] from #t


Srinika
Go to Top of Page
   

- Advertisement -