In high level programming language such as Java or Swift, if I want to use a string multiple times in the same program, I can define a string variable to represent that string, so to avoid typing the same string in multiple places. at the same time, making refracting the string easier
In Java
final String myStringConstant = "hello world";
In Swift
let myStringConstant = "hello world"
I was just wondering if it possible to do the same in Microsoft SQL Server? I have seen code that type the same string value in multiple places in the code, which makes it very easy to misspell the string in one of the place and therefore screw up the program. A string variable that used to represent the string would be extremely useful.
Declare @myStringConstant varchar(100). It will accept Size upto8000. If you want to store a string of length more than 8000 then useMaxGO, it's actually an SQLCMD script. SQLCMD has variables, which fulfil the same purpose. Despite the name, however, they're more like macros, since the replacement is purely textual, and the value cannot be set from an SQL command.