I'm thinking of creating a function of the format
FULL_TYPE_NAME(type_id, max_length)
that returns both the datatype and length in string format eg.:
FULL_TYPE_NAME (231,-1)
would return:
nvarchar(max)
Before I do this I wanted to check if tsql already has such a function (I haven't found one) or whether some kind soul out there has a ready made one that I can use. If not, then I'll write one and post it here.
Thanks in advance.
Here is my final function. I think it covers everything but feel free to correct me. I'll post my test script for this function later
This is my function. Thanks to HeavenCore for the start point
I called
to test it ( visual check only) Any suggestions for improvements much appreciated
A rough start would be something like this:
Note that this is only really good for char data types & only handles length, You'd need to implement a bit more logic if you want to use precision (decimals etc)
Also, you may want to add validation to only allow -1 length on certain user types
(For the sake of curiosity – why do you want to do this?)
This is my script for testing my function for anyone who would be interested.