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 |
Malhoosh
Starting Member
3 Posts |
Posted - 2011-10-25 : 04:24:13
|
I'm using Visual studio 2008 to create reports. I have a value EmployeeId which is an integer value.I've added an expression for a table field : =trim(Fields!EmployeeId.Value) I also made sure that "Fields!EmployeeId.Value" is seen as an integer as I've tried to multiply the value by 2, it worked fine. My question is how come it doesn't give me an error if trim function is supposed to take strings only ? |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-25 : 04:37:31
|
you did trimming before multiplication right? It underwent implicit conversion to string and applied the trim and them while multiplying it again underwent implicit conversion to convert it back to int.its analogous to below t-sql script. here also two implicit conversions are happeningdeclare @i intset @i=50select RTRIM(LTRIM(@i))*2 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
Malhoosh
Starting Member
3 Posts |
Posted - 2011-10-25 : 06:04:13
|
Thank you for your reply,Yes that solved the problem, I did not know that Trim() does implicit conversion, I thought it should give an error if I applied it on an int.Thank you again |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-10-25 : 06:08:25
|
Most functions will attempt an implicit conversion and only fail if that conversion fails.It's common when using date functions against strings.My opinion is that it shouldn't and you should always explicitly convert. It would make code a lot more involved but would save errors - and especially inefficient joins when the optimiser decides that it needs to convert one column and so can't use the index.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
Malhoosh
Starting Member
3 Posts |
Posted - 2011-10-25 : 08:00:20
|
Yes, I agree with you, explicit conversion will be more efficient. Thank you for your reply. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-26 : 01:01:19
|
quote: Originally posted by Malhoosh Thank you for your reply,Yes that solved the problem, I did not know that Trim() does implicit conversion, I thought it should give an error if I applied it on an int.Thank you again
depends on whether its compatible datatype. if it can it will undergo implicit conversion. if not it will throw error.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|