Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sysname 1

Status
Not open for further replies.

Denaeghel

Programmer
Apr 23, 2001
61
0
0
BE
I have a question about the types nvarchar and sysname. When I use the following query I get for nvarchar 2 types:

select sc.name as [name Field], st.name as [Name Type]
from sysobjects so
join syscolumns sc on sc.id = so.id
join systypes st on st.xtype = sc.xtype
where so.Xtype = 'u'
and so.name = 'TableName'

Result:
Field1 nvarchar
Field1 sysname

But when I use the following stored procedure:
exec sp_MShelpcolumns 'TableName'

Result:
Field1 nvarchar

Why I get by the first query 2 results?
 
sysname is just an alias for nvarchar(128) - it's not technically a different type. If you look in the systypes table you'll see they both have the same xtype value.

Change your query to use the xusertype column of the systypes table when joining it to the syscolumns table and you will only get the one row in the result.

BTW, it is recommended you use the INFORMATION_SCHEMA views rather than query the sys tables directly for things like this:

Code:
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'tablename'

--James
 
Ok thanks James

That was the answer that I was looking for

Karel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top