Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

MSSQL 2005 - Add ID value to ID column when INSERTING

// @TableName is obviously the TABLE name u use
// @ColumnName is obviously the COLUMN name u use

---Get next ID number
	DECLARE 
		@ID int
	
	IF (SELECT count(*) FROM @TableName ) > 0
		BEGIN
			SELECT @ID  = max(ColumnName ) from @TableName
			SET @ID = @ID + 1 
		END
	ELSE
	BEGIN
		SET @ID  = 1
	END

MSH host function in SQL server 2005

// part of a sql server CLR function, and example of hosting MSH in sql server 2005
    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlString sqlmsh(string input)
    {
        string output;
        Runspace runspace = RunspaceFactory.CreateRunspace();
        runspace.Open();
        Pipeline pipeline = runspace.CreatePipeline(input);
        MshObject myobj =   pipeline.Invoke()[0];
        if (myobj.BaseObject is XmlDocument)
         {
            output = (myobj.BaseObject as XmlDocument).InnerXml;
        } else
            output = myobj.ImmediateBaseObject.ToString();
            
        runspace.Close();
        return new SqlString(output);
    }
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS