October 18, 2007 at 10:26 am
C'mon Tony, get it right! Here is the code pasted in as a 'snippet' and using & e n s p ;
[font="Courier New"]USE [master]
GO
CREATE DATABASE [Test_DB] ON PRIMARY
(
NAME = N'Test_DB',
FILENAME = N'D:\MSSQL\Data\Test_DB.mdf' ,
SIZE = 102400KB ,
MAXSIZE = UNLIMITED,
FILEGROWTH = 102400KB
)
LOG ON
(
NAME = N'Test_DB_log',
FILENAME = N'E:\MSSQL\Logs\Test_DB_log.ldf' ,
SIZE = 51200KB ,
MAXSIZE = 2048GB ,
FILEGROWTH = 51200KB
)
COLLATE SQL_Latin1_General_CP1_CI_AS
GO[/font]
and here is is using nbsp; in a code block. The first time I pasted it in, it lost its indentation (if you paste it in, then preview it... is my best guess)
[font="Courier New"]USE [master]
GO
CREATE DATABASE [Test_DB] ON PRIMARY
(
NAME = N'Test_DB',
FILENAME = N'D:\MSSQL\Data\Test_DB.mdf' ,
SIZE = 102400KB ,
MAXSIZE = UNLIMITED,
FILEGROWTH = 102400KB
)
LOG ON
(
NAME = N'Test_DB_log',
FILENAME = N'E:\MSSQL\Logs\Test_DB_log.ldf' ,
SIZE = 51200KB ,
MAXSIZE = 2048GB ,
FILEGROWTH = 51200KB
)
COLLATE SQL_Latin1_General_CP1_CI_AS
GO[/font]
and here is the ensp version which never seems to lose its indentation. It will be all right in IE6 once you lose the ghastly grey background
[font="Courier New"]USE [master]
GO
CREATE DATABASE [Test_DB] ON PRIMARY
(
NAME = N'Test_DB',
FILENAME = N'D:\MSSQL\Data\Test_DB.mdf' ,
SIZE = 102400KB ,
MAXSIZE = UNLIMITED,
FILEGROWTH = 102400KB
)
LOG ON
(
NAME = N'Test_DB_log',
FILENAME = N'E:\MSSQL\Logs\Test_DB_log.ldf' ,
SIZE = 51200KB ,
MAXSIZE = 2048GB ,
FILEGROWTH = 51200KB
)
COLLATE SQL_Latin1_General_CP1_CI_AS
GO[/font]
Best wishes,
Phil Factor
October 23, 2007 at 12:34 pm
OK except for a daft problem, which is that the B***ding forum software sees the & # 1 6 0 ; & # 1 6 0 ; ) (without the spaces of course) and interprets the last two characters as a smiley (begorrah!)
[font="Courier New"]CREATE FUNCTION center
(
@String VARCHAR(8000),
@width INT,
@fillchar VARCHAR(10) = ' '
)
/*Returns a copy of @String centered in a string of length width, surrounded
by the appropriate number of fillChar characters
e.g.
select dbo.center('Help me please',100,'*')
select dbo.center('error',100,'*!=')
select dbo.center('error',null,null)
select dbo.center(null,null,null)
*/
RETURNS VARCHAR(8000)
AS BEGIN
IF @string IS NULL
RETURN NULL
DECLARE @LenString INT
DECLARE @LenResult INT
-- Declare the return variable here
SELECT @lenString = LEN(@String), @Fillchar = COALESCE(@Fillchar, ' '),
@width = COALESCE(@Width, LEN(@String) * 2)
SELECT @lenResult = CASE WHEN @LenString > @Width THEN @LenString
ELSE @width
END
RETURN STUFF(REPLICATE(@fillchar,
@lenResult / LEN(REPLACE(@FillChar, ' ', '|'))),
( @LenResult - LEN(@String) + 2 ) / 2, @lenString, @String)
END
GO[/font]
[font="Courier New"]ALTER FUNCTION dbo.[count]
(
@string VARCHAR(8000),
@Sub VARCHAR(8000),
@start INT = NULL,
@end INT = NULL
)
/* Returns the number of occurrences of substring sub in string s.
Select dbo.count('This is a nice string','[^a-z][a-z]',null,null)--wordcount (not include first word)
Select dbo.count('I''m henery the eighth I am I am','I am',null,null)
select dbo.count('45667892398','8',null,null)
*/
RETURNS INT
AS BEGIN
DECLARE @more INT
DECLARE @count INT
IF @string = NULL
RETURN NULL
SELECT @count = 0, @more = 1, @Start = COALESCE(@Start, 1),
@end = COALESCE(@end, LEN(@string))
SELECT @end = CASE WHEN @end > LEN(@string) THEN LEN(@string)
ELSE @end
END
WHILE @more <> 0
BEGIN
SELECT @more = PATINDEX('%' + @sub + '%',
SUBSTRING(@string, @Start, @End - @start + 1))
IF @more > 0
SELECT @Start = @Start + @more, @count = @count + 1
IF @start >= @End
SELECT @more = 0
END
RETURN @count
END
GO[/font]
Best wishes,
Phil Factor
May 30, 2014 at 3:30 am
hi All,
Can any one tell me how to paste the code in box rather than plain text.
i mean i would like to paste the code in table format in the forums.
May 30, 2014 at 6:33 am
click on the shortcut in the box on the left of the message pane
paste code between the two code blocks
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
May 30, 2014 at 8:00 am
as an additional hint for pasting code between the tags, add a couple of carriage returns between the opening and closing tags. Doing that will usually keep the code from changing the comparison operators (e.g. > and <).
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 5 posts - 16 through 19 (of 19 total)
You must be logged in to reply to this topic. Login to reply