Author |
Topic |
mehow
Starting Member
6 Posts |
Posted - 2013-03-06 : 05:35:22
|
Hello.I am a proper beginner in the world of sql, so i will be really thankful if someone can help me with my problem.I am trying to display all columns from a table and apply some formatting(formula) to only 1 maybe 2 of them.logic example:apply: DATEADD(day,CURDATE/1440, '01/01/1988')SELECT * and apply FROM tableONEI hope this makes sense! Cheers |
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-03-06 : 05:59:00
|
SELECT DATEADD(day,CURDATE/1440, '01/01/1988'), * FROM TableOne;If CurDate/1440 results in a figure with decimal places then they will automatically be ignored .. e.g. if the result of CurDate/1440 = 1.6 .. it will be considered as 1. Thanks!CheersMIK |
|
|
mehow
Starting Member
6 Posts |
Posted - 2013-03-06 : 06:04:45
|
the result of your query its that 1st column (A) stores the results of DATEADD and then from column 2(B) on theres is the rest of columns including CURDATEdateadd returns a date stored in database as BIGINT converted to a DATE format that excel reads as dd/mm/yyyy what i am trying to do its to display all columns but in place of CURDATE I'd like to have values already converted.So thank you for trying but this was not the solution :( |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-06 : 06:07:14
|
quote: Originally posted by mehow the result of your query its that 1st column (A) stores the results of DATEADD and then from column 2(B) on theres is the rest of columns including CURDATEdateadd returns a date stored in database as BIGINT converted to a DATE format that excel reads as dd/mm/yyyy what i am trying to do its to display all columns but in place of CURDATE I'd like to have values already converted.So thank you for trying but this was not the solution :(
How do you want values to get converted? whats the output format you're looking at?Also why is base datatype bigint if you're storing date values? ALways try to use proper datatype to avoid unnecessary conversion operations------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
mehow
Starting Member
6 Posts |
Posted - 2013-03-06 : 06:28:21
|
I have not designed the database I am working with. I am using 'Priority 15's database.the conversion is done with this statement : DATEADD(day,CURDATE/1440, '01/01/1988')I will try to explain this again.example:There is a table called TableOneThere are 3 columns in TableOne - NAMEA, CURDATE, NAMEBNAMEA is VARCHAR(20) CURDATE is BIGINT datatype ( value 13163040 represents 10/01/2013 )NAMEB is VARCHAR(20)Now, if I wanted to display all columns from TableOne so SELECT * FROM TableOneBut, if I wanted to apply this: DATEADD(day,CURDATE/1440, '01/01/1988') to column CURDATE and then display all columns - then how do i do that? |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-03-06 : 06:44:45
|
How you find that the value "13163040" represents 10/01/2013?CheersMIK |
|
|
mehow
Starting Member
6 Posts |
Posted - 2013-03-06 : 06:47:47
|
DATEADD(day,CURDATE/1440, '01/01/1988') <- converts to datedatabase im using uses BIGINT to represent dates. So 0 is 01/01/1988 then next day you add 0 + 1440. |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-03-06 : 06:57:31
|
Do you mean not to pull CurDate instead of it the "DATEADD(day,CURDATE/1440, '01/01/1988')"? If so may be this is something you're looking for SELECT NameA,DATEADD(day,CURDATE/1440, '01/01/1988'),NameB FROM TableOne;By the way there is no direct connection of CurDate with a date. You're take a raference '01/01/1988' and simply adding no of days to this date using the DateAdd function. Read this http://msdn.microsoft.com/en-us/library/ms186819.aspx and undestand the logic. I hope you'll be able to solve your problem yourself in case my guess is still not correct.CheersMIK |
|
|
mehow
Starting Member
6 Posts |
Posted - 2013-03-06 : 06:57:46
|
This is what I want: SELECT NAMEA, DATEADD(day,CURDATE/1440, '01/01/1988'), NAMEB FROM TableOnebut in reallife scenario there are 200 columns and I want to skip listing all 200 just to convert one column. |
|
|
mehow
Starting Member
6 Posts |
Posted - 2013-03-06 : 07:07:17
|
MIK, I know im using a reference - that's what i want to use cause I can't modify the database ( its got its own user interface and changing datatypes,logically thinking, is not allowed )I am pulling this data out of the database into an excel spreadsheet, and thats why I need to convert the 1234567 to a normal format date.so once again: This is what I want: SELECT NAMEA, DATEADD(day,CURDATE/1440, '01/01/1988'), NAMEB FROM TableOnebut in reallife scenario there are 200 columns and I want to skip listing all 200 just to convert one column.* If CURDATE is column number 55 then I was thinking of using aliases to name first 54 (ex. Batch1 ) then CURDATE then the remaining 56-200 (ex. Batch2 )so, then SELECT batch1, DATEADD(day,CURDATE/1440, '01/01/1988'), batch2 BUT theres gotta be an easier, neater, and better developed way of doing this! |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-03-06 : 07:08:34
|
just explicitly name them instead using * .. SELECT Column1,Column2,...,ColumnNForm TableNameCheersMIK |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-06 : 10:36:55
|
quote: Originally posted by mehow MIK, I know im using a reference - that's what i want to use cause I can't modify the database ( its got its own user interface and changing datatypes,logically thinking, is not allowed )I am pulling this data out of the database into an excel spreadsheet, and thats why I need to convert the 1234567 to a normal format date.so once again: This is what I want: SELECT NAMEA, DATEADD(day,CURDATE/1440, '01/01/1988'), NAMEB FROM TableOnebut in reallife scenario there are 200 columns and I want to skip listing all 200 just to convert one column.* If CURDATE is column number 55 then I was thinking of using aliases to name first 54 (ex. Batch1 ) then CURDATE then the remaining 56-200 (ex. Batch2 )so, then SELECT batch1, DATEADD(day,CURDATE/1440, '01/01/1988'), batch2 BUT theres gotta be an easier, neater, and better developed way of doing this!
you cant use alias to replace group of columns. You've to individually list them out!------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|