SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Code samples in the forums


Code samples in the forums

Author
Message
editor
editor
SSC Journeyman
SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)

Group: General Forum Members
Points: 87 Visits: 6
This is pasted in from rendered window within code blocks

USE [master]
GO
CREATE DATABASE [Test_DB_2] 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_2.ldf' ,
SIZE = 51200KB ,
MAXSIZE = 2048GB ,
FILEGROWTH = 51200KB
)
COLLATE SQL_Latin1_General_CP1_CI_AS
GO


Tony Davis
Tony Davis
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: Administrators
Points: 1361 Visits: 1162
Pasted from SSMS into design window using admin interface:

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

editor
editor
SSC Journeyman
SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)

Group: General Forum Members
Points: 87 Visits: 6
trying again as general forum member now that tab compression is off:

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
flares
flares
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 19
I've got no admin permissions, but here's a code block:


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



I have edited this too.
editor
editor
SSC Journeyman
SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)SSC Journeyman (87 reputation)

Group: General Forum Members
Points: 87 Visits: 6
this uses the new IFCODE prettifier and code tags and is pasted from the rendered html tab


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



Color is not preserved. Below is the same but pasted from the Source HTML tab:


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




Success!
Phil Factor
Phil Factor
SSCarpal Tunnel
SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)

Group: General Forum Members
Points: 4674 Visits: 3031
C'mon Tony, get it right! Here is the code pasted in as a 'snippet' and using & e n s p ;

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


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)

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





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
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




Best wishes,

Phil Factor
Simple Talk
Phil Factor
Phil Factor
SSCarpal Tunnel
SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)

Group: General Forum Members
Points: 4674 Visits: 3031
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!)

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


ALTER FUNCTION dbo.[count]
  
(
    
@string VARCHAR(8000),
    
@Sub VARCHAR(8000),
    
@start INT = NULL,
    
@end INT = NULL
  Wink
/* 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





Best wishes,

Phil Factor
Simple Talk
kbhanu15
kbhanu15
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1777 Visits: 344
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.
J Livingston SQL
J Livingston SQL
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11546 Visits: 37429
click on the [code=sql] 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

SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: General Forum Members
Points: 63499 Visits: 18570
as an additional hint for pasting code between the [code="sql"] 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 <Wink.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search