Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Code samples in the forums Expand / Collapse
Author
Message
Posted Tuesday, October 16, 2007 6:03 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, October 23, 2007 5:26 AM
Points: 77, 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

Post #411221
Posted Tuesday, October 16, 2007 6:27 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: Administrators
Last Login: Monday, October 20, 2014 1:22 PM
Points: 569, Visits: 1,033
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

Post #411237
Posted Wednesday, October 17, 2007 7:11 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, October 23, 2007 5:26 AM
Points: 77, 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
Post #411704
Posted Wednesday, October 17, 2007 7:14 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, March 14, 2008 7:14 AM
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.
Post #411705
Posted Thursday, October 18, 2007 10:16 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, October 23, 2007 5:26 AM
Points: 77, 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!
Post #412310
Posted Thursday, October 18, 2007 10:26 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Yesterday @ 3:40 AM
Points: 588, Visits: 2,554
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
Post #412318
Posted Tuesday, October 23, 2007 12:34 PM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Yesterday @ 3:40 AM
Points: 588, Visits: 2,554
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
  )
/* 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
Post #414052
Posted Friday, May 30, 2014 3:30 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, October 9, 2014 7:25 AM
Points: 988, Visits: 292
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.



Post #1575990
Posted Friday, May 30, 2014 6:32 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: 2 days ago @ 4:06 AM
Points: 1,917, Visits: 19,596
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
Post #1576037
Posted Friday, May 30, 2014 8:00 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 8:18 PM
Points: 17,824, Visits: 15,756
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 <).



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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Post #1576085
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse