valid_name

Description

Returns 0 if the specified string is not a valid identifier or a number other than 0 if the string is a valid identifier, and can be up to 255 bytes in length.

Syntax

valid_name(character_expression[, maximum_length])

Parameters

character_expression

is a character-type column name, variable, or constant expression of char, varchar, nchar or nvarchar type. Constant expressions must be enclosed in quotation marks.

maximum_length

is an integer larger than 0 and less than or equal to 255. The default value is 30. If the identifier length is larger than the second argument, valid_name returns 0, and returns a value greater than zero if the identifier length is invalid.

Examples

Example 1

Creates a procedure to verify that identifiers are valid:

create procedure chkname
@name varchar(30)
as
     if valid_name(@name) = 0
     print "name not valid"

Usage

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

Any user can execute valid_name.

See also

System procedure sp_checkreswords