Question : SQL Select: display only the first 800 characters from line 231 in a cell

The table FormDefinitions is as follows:

(<xaoFormID, char(75),>
 ,<xaoControlName, char(70),>
,<xaoClassID, char(35),>
,<xaoType, numeric(1,0),>
,<xaoProperties, text,>
,<xaoCode, text,>):

xaoCode contains over 900 lines of VBScript code. So doing a basic SQL select isn't very helpful when I only want to view only parts of the VBScript code.

Is it possible to get SQL Server 2008 to display the xaoCode values of the first 800 characters from line 231 ?

Thanks!

Answer : SQL Select: display only the first 800 characters from line 231 in a cell

I give up on not using a function, in fact I believe using a helper function will be a lot faster.
First create the function in the code box.
Then use this query:


select      F.*,
            convert(nvarchar(800),dbo.skipXtimes(F.xaoCode, CHAR(10), 230))
from FormDefinitions F
WHERE F.xaoFormID like 'fsi%'
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
CREATE function dbo.skipXtimes(@str nvarchar(max), @char char(1), @times int)
returns nvarchar(max)
as
begin
declare @test int
while @times > 0
begin
set @test = charindex(@char,convert(nvarchar(4000),@str))
if @test>0
	select @str=stuff(@str,1,@test,''), @times=@times-1
else
	set @times=0
end
return @str
end
GO
Random Solutions  
 
programming4us programming4us