You can create user snippet to generate first four letters of table name as table name alias as follows:
Add below snippet to the created user snippet:
{
"Create Select Statement": {
"prefix": "sqlselect",
"body": [
"SELECT * FROM ${1:TableName} as ${1/(.{4}).*/$1/}"
],
"description": "Create a SELECT statement for a table"
}
}
In this snippet, ${1/(.{4}).*/$1/}
is using a regular expression transform to capture the first 4 characters of the table name and apply them as the alias. The expression works as follows:
(.{4})
: This captures the first 4 characters of the table name.
.*
: This matches any remaining characters in the table name.
$1
: This references the captured group from the first part of the expression, which are the first 4 characters of the table name.
I formatted above snippet as document and opened new query tab typed sqlselect
and pressed tab I got below script:
SELECT * FROM TableName as TableName
Entered the table name and pressed tab I got required output as mentioned below:
SELECT * FROM student as stud
