all groups > sql server programming > february 2005 >
You're in the

sql server programming

group:

HOST_NAME length


HOST_NAME length Gary K
2/2/2005 10:25:05 PM
sql server programming: Sorry 2 bug, but I would like to know how long a variable should be to handle
the maximum HOST_NAME length? All the documentation tells you is the datatype
RE: HOST_NAME length mark baekdal
2/2/2005 10:49:04 PM
Hello Gary.

The example in books online creates a table using the HOST_NAME() function
as the dri default and uses NCHAR(30) as the column data type and length:

CREATE TABLE Orders
(OrderID INT PRIMARY KEY,
CustomerID NCHAR(5) REFERENCES Customers(CustomerID),
Workstation NCHAR(30) NOT NULL DEFAULT HOST_NAME(),
OrderDate DATETIME NOT NULL,
ShipDate DATETIME NULL,
ShipperID INT NULL REFERENCES Shippers(ShipperID))




regards,
Mark Baekdal
http://www.dbghost.com
http://www.innovartis.co.uk
+44 (0)208 241 1762
Database change management for SQL Server




[quoted text, click to view]
Re: HOST_NAME length Jacco Schalkwijk
2/3/2005 10:28:36 AM
In general internal names in SQL Server are of datatype SYSNAME, which is
equivalent to NVARCHAR(128).

This is conformed for HOST_NAME() by:
SELECT SQL_VARIANT_PROPERTY(HOST_NAME(), 'BaseType') -- NVARCHAR
SELECT SQL_VARIANT_PROPERTY(HOST_NAME(), 'MaxLength') -- 256

MaxLength returns the length in bytes and so has to be divided by 2 to
arrive at the number of characters because it is a double-byte datatype.

--
Jacco Schalkwijk
SQL Server MVP


[quoted text, click to view]

AddThis Social Bookmark Button