Skip to content

Instantly share code, notes, and snippets.

-- This is only a helper VIEW since currently you can not use RAND() in a UDF
-- USAGE : SELECT number FROM vRand
CREATE VIEW vRand
AS
SELECT RAND() AS 'number'
GO
/* ----------------------------------------------------------------------------
Simple tsql C# vo class generator
Pass in the name of the table to create a class for, and the name for your
resulting class
Assumptions :
- This script dumps a C# class representation of a sql database table
- MS tsql datatypes were used for C# converstion
/*
Helper function to select a text value in a <select>
If the value doesn't exist, selectedIndex = 0
*/
function selectedValue(menu_id, value)
{
// get menu
var c_menu = document.getElementById(menu_id);
if( c_menu )
-- var to hold random value
declare @field_val int
-- create table var to hold value range [ 0, 512, 1024, 1536, 2048 ]
SELECT 0 AS 'num'
INTO #temp
-- insert data into table var
INSERT INTO #temp VALUES ( 512 )
INSERT INTO #temp VALUES ( 1024 )
-- define our data table
WITH data( num )
AS
(
-- our value range in a single query
SELECT 0 AS 'num'
UNION
SELECT 512 AS 'num'
UNION
SELECT 1024 AS 'num'
var str = "";
for( xx in map )
{
// append
str += xx + " : " + map[ xx ] + "\n";
// dump when it gets long
if( str.length >= 300 )
{
alert( str );
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#EFEFEF" backgroundImage="">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.utils.ArrayUtil;
/**
* - Create a custom object ( this could be a custom class object )
/*
borrowed from : http://www.kodyaz.com/articles/t-sql-convert-split-delimeted-string-as-rows-using-xml.aspx
Use this function to split values in a comma delimited list into a TABLE variable
with one column named 'val', and a row for each value in your list.
usage : SELECT * FROM dbo.Split(N'a,b,c,d,e', ',')
--
USE SmartEarth
/*
Example of a dynamic PIVOT against a varchar column from the Adventureworks database
References :
PIVOT & UNPIVOT
http://msdn.microsoft.com/en-us/library/ms177410.aspx
COALESCE
http://msdn.microsoft.com/en-us/library/ms190349.aspx
USE AdventureWorks;
-- create a comma delimited list of CountryRegionCode per CurrencyCode
SELECT CurrencyCode,
MAX( COALESCE( CountryRegionCode + ', ', '') + CountryRegionCode ) AS 'RegionCodes'
FROM Sales.CountryRegionCurrency