SQL Create Table ????

Results 1 to 2 of 2

Thread: SQL Create Table ????

  1. #1
    Join Date
    Dec 1969

    Default SQL Create Table ????

    Hello all,<BR><BR>Would anyone know the correct syntax for an SQL query that would do the following:<BR><BR>I want to create a table based on the fields in another table. Except the new table <BR>should have a column which is made up of a diffrence of dates......<BR><BR>Table1 has these fields: <BR><BR>DateEntered (Date field eg. 02/06/01(d/m/y)<BR>Numberofdays (Date field ***No data***** (d/m/y)<BR><BR>The table I want to create from this table should have the following : <BR><BR>Table2<BR>DateEntered (Date field eg. 02/06/01(d/m/y)<BR>Numberofdays ***** this must be Todays Date - DateEntered (Table1) e.g <BR>02/06/01 - 01/06/01 = 1 day.<BR><BR>I know I can use the Select Into query to create the table, but where in the query do i but the calculation for Todays Date - DateEntered? <BR><BR>SQL= SELECT DateEntered,Numberofdays DateDiff [mm, &#039; DateEntered &#039; ; &#039;GetDate()&#039;]<BR>INTO Table2<BR>FROM Table1<BR><BR>Please help me if you can.... any advice would be appreciated as i have a deadline to get this done by!!<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: SQL Create Table ????

    Depends on the DB you are using!<BR><BR>*IF* you are using SQL Server--and you appear to be--then you probably can do it via:<BR><BR>SELECT DateEntered, DateDiff(d,DateEntered,GetDate()) AS NumberOfDays<BR>INTO Table2<BR>FROM Table1<BR><BR>Note that your NumberOfDays field will be an INTEGER field! As the number of days is *not* a valid Date/Time value...it is simply a count, which is an integer. You do *NOT* want to use [...] for functions, as you tried to do. You do *NOT* want to use &#039;...&#039; around field names or function names.<BR><BR>I *think* that the only difference if you meant to use this with Access would be to put &#039;...&#039; around the &#039;d&#039; in the DateDiff:<BR><BR>SELECT DateEntered, DateDiff(&#039;d&#039;,DateEntered,GetDate()) AS NumberOfDays<BR>INTO Table2<BR>FROM Table1<BR><BR>UNTESTED!<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts