xTxT Documentation

Parameterized Database Query Example

[ Show 10 ] [ Show 20 ] [ Show 30 ]

Parameterized Queries

xTxT also supports the use of document-level parameters, which are typically passed in through the Uri querystring. These parameters can be used in Sql statements to supply variable settings to the Sql request.


Defining Default Parameters

/param Qty 

The /param tag allows you to define a default value for any parameter, which is used if no matching querystring parameter is passed in. This ensures that the page can execute properly even if no querystring has been specified.

Default parameters can also be used as sort of a page-level constant, for convenience if certain aspects of the page change regularly.


The sql statement for this page is defined as;

select top {Qty}
	case c.Enabled
		when 1 then ''
		when 0 then 'text-decoration: line-through'
		end _css,
	'/admin/medias/media/view/?MediaID=' + cast (m.MediaID as varchar) _link,
	mt.Name MediaType
from Media m
join Company c on c.CompanyID = m.MediaID
join MediaType mt on mt.MediaTypeID = m.MediaTypeID
order by c.Name asc

Note the {Qty} definition. Parameter placements are defined using curly braces { } and the name of the parameter you've defined.