Groups | Blog | Home
all groups > sql server new users > april 2007 >

sql server new users : Select



Aleks
4/10/2007 10:44:06 AM
I have the following values in a field named (sn_font).

Opaque=1;Font=Times New
Roman;FontSize=10;FontBold=0;FontItalic=0;FontUnderline=0;TextColor=0,0,0;BackColor=255,255,204;Printable=1


I need to make a select statement that will give a result such as "0".

If I need to select only the value for "FontItalic".

How can I do this ? How can I only select the value after the sign '=' for
one of the items above if it is all stored in one line in the same field ?

A

Kamran
4/10/2007 12:00:48 PM
Hi,

If there are no spaces before and after '=' sign then Value is helpful,
otherwise Value2 gives a general solution for any property:
--
create table #test (sn_font varchar(200))
insert into #test values ('Opaque=1;Font=Times New
Roman;FontSize=10;FontBold=0;FontItalic=
0;FontUnderline=0;TextColor=0,0,0;BackColor=255,255,204;Printable=1')
--
declare @cSearch varchar(20)
set @cSearch = '%FontItalic%'
--
select SUBSTRING(sn_font , PATINDEX ( @cSearch , sn_font ) + 11 , 1) as
Value
--
,SUBSTRING(SUBSTRING(sn_font , PATINDEX ( @cSearch , sn_font ) ,
len(sn_font)),
PATINDEX ('%=%', SUBSTRING(sn_font , PATINDEX ( @cSearch , sn_font ) ,
len(sn_font))) +1,
PATINDEX ('%;%', SUBSTRING(sn_font , PATINDEX ( @cSearch , sn_font ) ,
len(sn_font)))
- PATINDEX ('%=%', SUBSTRING(sn_font , PATINDEX ( @cSearch , sn_font ) ,
len(sn_font)))-1) as Value2
from #test

--
drop table #test
--

HTH

Kamran

[quoted text, click to view]

Aleks
4/10/2007 12:07:12 PM
I actually dont want to create another table, I just want to select the
value and create a recordset, if ran in query analizer simply see the
result.

A


[quoted text, click to view]

Kamran
4/10/2007 12:34:33 PM
Hi Aleks,

If you are referring to table '#test' this is a temp table for displaying
example more clearly. You only need to use 'declare..., set... and
SELECT...' statements in query analyzer (with your table name instead of
#test in SELECT).

Regards,

Kamran

[quoted text, click to view]

AddThis Social Bookmark Button