New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets matching tags of sql
SQL
/*--------------------------------------------------------*/
/*------Author:-----ksimons-------------------------------*/
/*------Purpose:----Hurt-Brains---------------------------*/
/*----*/DECLARE @T as Table (i int)Insert into @t   /*----*/
/*----*/Select top 1000 ROW_NUMBER()OVER(order by   /*----*/
/*----*/s.id) From sysobjects s, sysobjects         /*----*/
/*----*/Select Cast(I as varchar)+reverse(substring /*----*/
/*----*/('httsdndr', Cast(((((ceiling((abs(((I/10)- /*----*/
/*----*/1)%20))/((abs(((I/10)-1)%20))+0.1)))* (((1- /*----*/
/*----*/ceiling((abs(I-1)%10)/((abs(I-1)%10)+.2)))+ /*----*/
by Kris Simons   Monday @ 3:47pm
19 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Runtime.Serialization;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq.Expressions;
by Jerry Nixon   March 05, 2010 @ 9:36am
Tags: C#, LINQ, LINQ2SQL
20 Views
no comments
 
SQL
declare @x int, @y int, @z int
set @x = 1
set @y = 2
set @z = 1
 
-- returns @x (because not equal)
select case when @x = @y then null else @x end
 
-- returns null (because equal)
select case when @x = @z then null else @x end
by Jerry Nixon   March 05, 2010 @ 9:11am
13 Views
no comments
 
SQL
'1/1/2000 1:30 AM' != '1/1/2000 1:31 AM'
 
-- ///
 
DECLARE @x datetime
SET @x = GETDATE()
SET @x = CONVERT(varchar, @x, 101)
 
-- ///
by Jerry Nixon   March 05, 2010 @ 8:53am
Tags: SQL, DateTime
14 Views
no comments
 
SQL
-- clean up any test artifacts
if object_id('test1') is not null drop table test1
if object_id('test2') is not null drop table test2
if object_id('test') is not null drop view test
GO
 
-- the partition column must have a CHECK 
-- and be part of the PRIMARY KEY
create table test1 (col1 int 
    primary key check (col1 = 1), col2 varchar(50))
by Jerry Nixon   March 05, 2010 @ 8:47am
12 Views
no comments
 
C#
<#@ template language="C#v3.5" hostspecific="True" debug="True" #> 
<#@ output extension="cs" #>
<#@ assembly name="Microsoft.SqlServer.ConnectionInfo" #>
<#@ assembly name="Microsoft.SqlServer.Smo" #>
<#@ assembly name="System.Data" #>
<#@ import namespace="Microsoft.SqlServer.Management.Smo" #>
<#@ import namespace="Microsoft.SqlServer.Management.Common" #>
<#@ import namespace="System.Data.SqlClient" #>
<#@ import namespace="System.Collections.Specialized" #>
<#
by Rob   March 04, 2010 @ 7:47am
Tags: T4, Sql, c#
26 Views
no comments
 
SQL
select 
    i.id AS IssueID,
    p.pname,
    ISNULL(c.cname,'') AS ComponentName,
    ISNULL(pv.vname,'') AS VersionName,
    pv.RELEASED AS Released,
    i.summary,
    i.DESCRIPTION,
    i.TIMEORIGINALESTIMATE/3600 AS HoursOriginalEstimate,
    i.TIMEESTIMATE/3600 as HoursEstimate,
by Matt Ritchie   March 02, 2010 @ 5:53pm
Tags: sql, jira
23 Views
no comments
 
SQL
SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) 
select convert(varchar(10),getdate(),121)
CONVERT(VARCHAR,start_dttm,111)
by Stefan Sandström   February 23, 2010 @ 12:42am
Tags: sql, date
11 Views
no comments
 
SQL
DECLARE @ParamFromDate datetime
DECLARE @ParamToDate datetime
DECLARE @ParamQueues varchar(50)
DECLARE @CurrentDate DATETIME
DECLARE @L_Start varchar(50)
DECLARE @L_End varchar(50)
DECLARE @LSQL as varchar(1500)
DECLARE @LCOL as varchar(50)
DECLARE @TableName1 varchar(50)
DECLARE @TableName2 varchar(50)
by Thom Lamb   February 12, 2010 @ 1:34pm
14 Views
no comments
 
function global:out-zip($path){
$files = $input
  
if (-not $path.EndsWith('.zip')) {$path += '.zip'} 
 
if (-not (test-path $path)) { 
  set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) 
} 
$zip=resolve-path($path)
$ZipFile = (new-object -com shell.application).NameSpace( "$zip" ) 
by Eric Hexter   January 17, 2010 @ 6:34pm
203 Views
1 comments
 
SQL
CREATE TABLE table1 (id int);
INSERT INTO table1 VALUES (1);
INSERT INTO table1 VALUES (2);
INSERT INTO table1 VALUES (3);
 
CREATE TABLE table2 (id int);
INSERT INTO table2 VALUES (2);
INSERT INTO table2 VALUES (3);
 
CREATE TABLE table3 (id int);
by Luciano Evaristo Guerche (Gorše)   January 13, 2010 @ 9:54am
47 Views
2 comments
 
SQL
SELECT 'ALTER TABLE ' + TABLE_SCHEMA + '.[' + TABLE_NAME +
'] DROP CONSTRAINT [' + CONSTRAINT_NAME + ']'
FROM information_schema.table_constraints
WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
by Steve Wright   January 07, 2010 @ 7:57am
Tags: sql
33 Views
no comments
 
SQL
SELECT table_name=sysobjects.name,
         column_name=syscolumns.name,
         datatype=systypes.name,
         length=syscolumns.length
    FROM sysobjects 
    JOIN syscolumns ON sysobjects.id = syscolumns.id
    JOIN systypes ON syscolumns.xtype=systypes.xtype
   WHERE sysobjects.xtype='U'
ORDER BY sysobjects.name,syscolumns.colid
by caltuntas   January 03, 2010 @ 11:37pm
Tags: sql
19 Views
no comments
 
SQL
SELECT TOP {#} {Fields} 
FROM {table} 
ORDER BY newid()
by kopelli   December 31, 2009 @ 1:55pm
Tags: sql
22 Views
no comments
 
SQL
DECLARE @str nvarchar(128)
SET @str = '[AdventureWorks].[dbo].[ErrorLog]'
 
SELECT    ISNULL(PARSENAME(@str, 4), @@SERVERNAME) AS [ServerName],
        ISNULL(PARSENAME(@str, 3), DB_NAME()) AS [DatabaseName],
        ISNULL(PARSENAME(@str, 2), ISNULL([default_schema_name], 'dbo')) AS [SchemaName],
        PARSENAME(@str, 1) AS [ObjectName]
       
FROM [sys].[database_principals]
WHERE [name] = SYSTEM_USER
by kopelli   December 31, 2009 @ 6:32am
41 Views
no comments
 
 
procedure TForm1.SearchButtonClick(Sender: TObject);
var  HurricaneName: string;
begin
HurricaneName := HurricaneSearchBox.text;
with ADOQuery1 do begin
  Close;
  SQL.Text := 'SELECT * FROM Huracanes WHERE Huracanes.Nombre =' + tblname;
  Open;
end;
by Joel   November 30, 2009 @ 5:53am
Tags: sql, adoquery
26 Views
no comments
 
SQL
create table some_base_table (
    batch_id        int not null primary key clustered,
    batch_name      varchar(250) not null,
    some_parm       int null,
    some_parm2      int null
)
 
insert some_base_table ( batch_id, batch_name, some_parm, some_parm2 )
    values( 1, 'hello fred', 1, 2 )
insert some_base_table ( batch_id, batch_name, some_parm, some_parm2 )
by ivanrdgz   October 24, 2009 @ 10:41pm
34 Views
no comments
 
SQL
CREATE TABLE SomeBaseTable
(
 BatchId int NOT NULL PRIMARY KEY,
 BatchName varchar(250) NOT NULL,
 AnIntParameter int NULL,
 AnotherIntParameter int NULL
)
GO
 
INSERT INTO SomeBaseTable
by Luciano Evaristo Guerche (Gorše)   October 21, 2009 @ 7:50am
115 Views
1 comments
 
C#
// works as expected
public wws_Item LoadBySku(string sku)
{
    Expression< Func<wws_Item, bool> > func = itm => itm.Sku == sku;
 
    Entity = Context.wws_Items.Where(func).SingleOrDefault();
    if (Entity != null)
        OnLoaded(Entity);
 
    return this.Entity;
by Rick Strahl   October 04, 2009 @ 5:02pm
172 Views
no comments
 
C#
 StockContext context = new StockContext();
 User user = context.Users.Where( uss => uss.Pk == 1).SingleOrDefault();
 Response.Write(user.FullName + "<br>"); 
 user.FullName = user.FullName + "!";
 
 
 StockContext context2 = new StockContext();
 User user2 = context.Users.Where(uss => uss.Pk == 1).SingleOrDefault();
 Response.Write(user2.FullName + "<br>");
 user2.FullName = user2.FullName + "!";
by Rick Strahl   September 27, 2009 @ 2:34pm
78 Views
no comments
 
#!/bin/bash
(while(true); do  \
(mysql -e 'show innodb status \G' | grep undo\ log\ entries ; sleep 1 ;  \
mysql -e 'show innodb status \G' | grep undo\ log\ entries ) |    \
egrep '[0-9][0-9][0-9][0-9]' |awk '{print $10;}' ; done ) | \
perl -e '$t = ROWS_IN_TABLE; while(1) { \
$n ++; $nn; $a = <>; $b = <>; $nn += ($b-$a); \
printf "Rate: %d, avg: %d, %0.3f%% complete, done in %d sec\n", \
$b-$a, $nn/$n, ($b/$t)*100, ($t-$b)/($nn/$n); }';
by yuyu1984   September 21, 2009 @ 7:06pm
Tags: mysql, monitor
41 Views
no comments
 
SQL
DECLARE @begin DATETIME
DECLARE @end DATETIME
SET @begin = '2009/09/17 00:00'
SET @end =  '2009/09/17 18:00'
;
SELECT 'total count' = COUNT(1)
FROM TB_TXN_REC
WHERE CREATE_TIME_STAMP BETWEEN @begin AND @end 
;
SELECT 'avg response time(ms)' =  AVG( DATEDIFF(MILLISECOND, CREATE_TIME_STAMP, UPDATE_TIME_STAMP)  ) 
by Robin Su   September 17, 2009 @ 8:38am
54 Views
no comments
 
param (
    [string]$server = ".",
      [string]$instance = $(throw "a database name is required"),
    [string]$query
)
 
$connection = new-object system.data.sqlclient.sqlconnection( `
    "Data Source=$server;Initial Catalog=$instance;Integrated Security=SSPI;");
    
$adapter = new-object system.data.sqlclient.sqldataadapter ($query, $connection)
by David R. Longnecker   August 31, 2009 @ 12:07pm
301 Views
2 comments
 
SQL
SELECT SERVERPROPERTY('BuildClrVersion') AS [BuildClrVersion]
GO
SELECT SERVERPROPERTY('Collation') AS [Collation]
GO
SELECT SERVERPROPERTY('CollationID') AS [CollationID]
GO
SELECT SERVERPROPERTY('ComparisonStyle') AS [ComparisonStyle]
GO
SELECT SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS [ComputerNamePhysicalNetBIOS]
GO
119 Views
no comments
 
C#
public IQueryable<Role> GetRolesByUserId(int userId)
{
    var userRoles = from userRole in db.UserRoles
                            where userRole.UserId == userId
                            select userRole.RoleId;
 
            return from roles in db.Roles
                        where userRoles.Contains(roles.RoleId)
                        select roles;
}
by Justin   August 05, 2009 @ 3:29pm
144 Views
no comments
 
brought to you by:
West Wind Techologies


If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate