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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Pls pls pls ASAP!!!

Author  Topic 

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2004-12-11 : 01:45:17
help... i need to extract this string with the following arguments...

1. @command
2. @FamilyNane
3. @FirstName
4. @CellNo
5. @PIN

"REG ORAN/RODERICK 09197264062 1234"


result shoul be this....

1. @command = REG
2. @FamilyNane = ORAN
3. @FirstName = RODERICK
4. @CellNo = 09197264062
5. @PIN = 1234


pls ASAP!


I think we can use xp_sscanf

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2004-12-11 : 02:15:43
I don't know what the rules are but it looks like you could use patindex and substring to pull out the portions of the string that you want. See BOL (Books Online) for details on vboth of these.

HTH

=================================================================

Happy Holidays!
Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2004-12-11 : 02:27:05
The syntax for the string....

"REG ORAN/RODERICK 09197264062 1234"

is

@command + [space] + @FamilyNane + "/" + @FirstName + [space] + @CellNo + [space] + @PIN


now i have to extract it.....





Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2004-12-11 : 02:36:42
actually i have this code ...

quote:
DECLARE @Command varchar (10), @Lname varchar (30),
@Fname varchar (30), @CellNo varchar (20), @PIN varchar (4)
EXEC master..xp_sscanf 'REG ORAN/ODERICK 09197264062 1234',
'%s %s %s %s %s' ,
@Command OUTPUT, @Lname OUTPUT, @Fname OUTPUT, @CellNo OUTPUT, @PIN OUTPUT
SELECT @Command, @Lname, @Fname, @CellNo, @PIN




however results is this...
1. @command = REG
2. @FamilyNane = ORAN/RODERICK
3. @FirstName = 09197264062
4. @CellNo = 1234
5. @PIN = NULL



Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2004-12-11 : 02:56:42
Or you can ignore my advice and just do it your way... Either way, I'm happy.

HTH

=================================================================

Happy Holidays!
Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2004-12-11 : 03:12:10
pLEASE anybody can help me?

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-12-11 : 03:59:12
You know, you can try Bustaz advice...
declare @s varchar(100)
set @s = 'REG ORAN/RODERICK 09197264062 1234'

select
parsename(replace(@s,' ','.'),4),
parsename(replace(parsename(replace(@s,' ','.'),3),'/','.'),2),
parsename(replace(parsename(replace(@s,' ','.'),3),'/','.'),1),
parsename(replace(@s,' ','.'),2),
parsename(replace(@s,' ','.'),1)


rockmoose
Go to Top of Page
   

- Advertisement -