| Author |
Topic |
|
phanicrn
Starting Member
42 Posts |
Posted - 2007-11-06 : 12:45:34
|
| what'z the difference between char & varchar, like i am doing a cast function, which one should be used.. |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-11-06 : 12:49:14
|
| varchar is a variable length datatype so it will always hold as many bytes at there is datachar is fixed length datatype and will pad shorter data with spaces to fill it's capacity_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
phanicrn
Starting Member
42 Posts |
Posted - 2007-11-06 : 13:08:20
|
| basically iam converting interger datatype using cast function into char..month column in database has int16. values as 1,2,3,.....now i am creating a calculation with case, which show as month=1 then "january' this datatype being generated as character. now when i am sorting on month(calculated column) its performing sorting on character. values as "Aug", "apr"...but i want my values to appear as January, February.. How do we do this.. |
 |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2007-11-06 : 21:54:04
|
| What's length of the char column? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-11-07 : 01:04:06
|
| or you can usedatename(month,dateadd(month,month_number-1,0)) instead of multiple CASEsMadhivananFailing to plan is Planning to fail |
 |
|
|
phanicrn
Starting Member
42 Posts |
Posted - 2007-11-07 : 11:46:41
|
| length of char column is 9. and this datename(month,dateadd(month,month_number-1,0)) didnt work. |
 |
|
|
dataguru1971
Master Smack Fu Yak Hacker
1464 Posts |
Posted - 2007-11-07 : 12:01:02
|
| replace "month_number" with your column name containing the number and it will workthis:datename(month(dateadd(m,1-1,0)) produces "January" |
 |
|
|
phanicrn
Starting Member
42 Posts |
Posted - 2007-11-07 : 16:26:43
|
| replace "month_number" with your column name containing the number and it will workthis:datename(month(dateadd(m,1-1,0)) produces "January"in this example, datename(month-- refers to character column or to return as "month" |
 |
|
|
dataguru1971
Master Smack Fu Yak Hacker
1464 Posts |
Posted - 2007-11-07 : 16:54:12
|
quote: Originally posted by phanicrn replace "month_number" with your column name containing the number and it will workthis:datename(month(dateadd(m,1-1,0)) produces "January"in this example, datename(month-- refers to character column or to return as "month"
Not quite, in this example datename(month...refers to the month property of the resulting date found in the dateadd sequence. in the OP's example, Month_Number represents his column of numbers. This is quite evident if you actually put my code in the QA. |
 |
|
|
arorarahul.0688
Posting Yak Master
125 Posts |
Posted - 2007-11-08 : 02:22:27
|
quote: Originally posted by madhivanan Use the logic suggested herehttp://sqlteam.com/forums/topic.asp?TOPIC_ID=92192MadhivananFailing to plan is Planning to fail
hi madhivananHappy diwali to you and your familyRahul Arora MCA 07 BatchNCCE Israna, PanipatHRY, INDIA######################IMPOSSIBLE = I+M+POSSIBLE |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-11-09 : 01:00:06
|
quote: Originally posted by arorarahul.0688
quote: Originally posted by madhivanan Use the logic suggested herehttp://sqlteam.com/forums/topic.asp?TOPIC_ID=92192MadhivananFailing to plan is Planning to fail
hi madhivananHappy diwali to you and your familyRahul Arora MCA 07 BatchNCCE Israna, PanipatHRY, INDIA######################IMPOSSIBLE = I+M+POSSIBLE
Thanks and wishing you the same MadhivananFailing to plan is Planning to fail |
 |
|
|
|