Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
herbjorn
Starting Member
8 Posts |
Posted - 2005-02-28 : 09:35:55
|
Hi,I'm trying to do the following:select cast(12345 as nvarchar)The result is (No column name)12345So far so good. If I use variables like this:declare @int intdeclare @var nvarchar(100)select @int = 12345select @var= cast(@int as nvarchar)select @varThe result is(No column name)12345However, if I use this code inside a function the result is(No column name)1Why? What can I do to achieve the desired result inside a function? Thanx |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-02-28 : 09:41:47
|
Well...I would suggest that you always define the length of your char datatypes...but I don't have the problem you mentionCREATE FUNCTION myUDF99 (@int int)RETURNS nvarchar(100)AS BEGIN DECLARE @var nvarchar(100) SET @var= cast(@int as nvarchar) RETURN @var ENDGOSELECT dbo.myUDF99(12345)GODROP FUNCTION myUDF99GO Brett8-) |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-02-28 : 09:42:12
|
you need the bold part:select @var= cast(@int as nvarchar(100))Go with the flow & have fun! Else fight the flow |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-02-28 : 09:44:27
|
| If you change the RETURNS part to be RETURNS nvarchar, then you get the results you mention.Always supply the lengthBrett8-) |
 |
|
|
herbjorn
Starting Member
8 Posts |
Posted - 2005-02-28 : 09:51:37
|
Hi!The problem was that I hadn't specified the length of the RETURNS clause. When I had problems it was like this:RETURNS nvarcharNow that it is working it isRETURNS nvarchar(100)THANX! quote: Originally posted by X002548 If you change the RETURNS part to be RETURNS nvarchar, then you get the results you mention.Always supply the lengthBrett8-)
|
 |
|
|
|
|
|