Basic

/*ds ParameterName*/DummyValue

Syntax remarks

Do not put a space between the dummy value and comment.

good code
	/*ds minage*/20 <= Age

bad code
	/*ds minage*/ 20 <= Age

EQUALS

code
SELECT
	*
FROM
	Employees
WHERE
	/*ds minage*/20 <= Age AND
	Age <= /*ds maxage*/29

runtime
SELECT
	*
FROM
	Employees
WHERE
	@minage <= Age AND
	Age <= @maxage
--minage=20, maxage=29

LIKE

code
SELECT
	*
FROM
	Employees
WHERE
	Name LIKE /*ds name*/'A%'

runtime
SELECT
	*
FROM
	Employees
WHERE
	Name LIKE @name
--name=A%

BETWEEN

code
SELECT
	*
FROM
	Employees
WHERE
	Age Between /*ds minage*/30 AND /*ds maxage*/40

runtime
SELECT
	*
FROM
	Employees
WHERE
	Age Between @minage AND @maxage
--minage=20, maxage=29

IN

code
SELECT
	*
FROM
	Employees
WHERE
	Age IN /*ds age*/(20,21,22)

runtime
SELECT
	*
FROM
	Employees
WHERE
	Age IN (@age_0, @age_1, @age_2, @age_3, @age_4, @age_5, @age_6, @age_7, @age_8)
--age_0=20, age_1=21, age_2=22, age_3=30, age_4=31, age_5=32, age_6=40, age_7=41, age_8=42

Advance

IF

/*ds if ParameterName != null*/ Any Code /*ds end if*/

code
SELECT
	*
FROM
	Employees
WHERE
/*ds if name != null*/
	Name LIKE /*ds name*/'A%' 
/*ds end if*/

runtim at parameter is nothing
SELECT
	*
FROM
	Employees

runtim at parameter has any
SELECT
	*
FROM
	Employees
WHERE
	Name LIKE @name
--name=A%

WHERE

/*ds begin*/ Where or OrderBy Code /*ds end begin*/

code
SELECT
	*
FROM
	Employees
/*ds begin*/
WHERE
/*ds if name != null*/
	Name LIKE /*ds name*/'A%' 
/*ds end if*/
/*ds if age != null*/
	AND Age = /*ds age*/30 
/*ds end if*/
/*ds if prefecture != null*/
	AND Prefecture = /*ds prefecture*/'Tokyo'
/*ds end if*/
/*ds end begin*/

runtim at parameter is nothing
SELECT
	*
FROM
	Employees

runtim at parameter has any
SELECT
	*
FROM
	Employees
WHERE
	Name LIKE @name
	AND Age = @age
--name=A%, age=30

ORDER BY (Hard cording)

/*ds $ParameterName*/DummyValue

code
SELECT
	*
FROM
	Employees
/*ds begin*/
ORDER BY
	/*ds $orderby*/Name,Age,Prefecture
/*ds end begin*/

runtime at pramater is nothing
SELECT
	*
FROM
	Employees

runtime at parameter has any (Note to SQL Injection)
SELECT
	*
FROM
	Employees
ORDER BY
	Name, Age DESC, Prefecture

Last edited Sep 9, 2014 at 1:55 PM by mk3008, version 2