Call now: (800) 766-1884  



 Home


 SQL Server Tips
 SQL Server Training

 SQL Server Consulting
 SQL Server Support
 SQL Server Remote DBA



 Articles
 Services
 SQL Server Scripts
 Scripts Menu



 

 

 

 
 

SQL Server

SQL Server Tips by Gama and Naughter Consulting

 


Testing the Code

To test the XP support, a simple SQL Script called “test.sql” is located in the XP_ASTRO directory. We first must register all the XP’s as per normal. This can be achieved using:

EXEC master..sp_addextendedproc 'XP_ASTRO_DATE2JULIAN', 'XP_ASTRO.dll'
EXEC master..sp_addextendedproc 'XP_ASTRO_JULIAN2DATE', 'XP_ASTRO.dll'
EXEC master..sp_addextendedproc 'XP_ASTRO_DELTAT', 'XP_ASTRO.dll'
EXEC master..sp_addextendedproc 'XP_ASTRO_SPRING_EQUINOX', 'XP_ASTRO.dll'
EXEC master..sp_addextendedproc 'XP_ASTRO_SUMMER_SOLSTICE', 'XP_ASTRO.dll'
EXEC master..sp_addextendedproc 'XP_ASTRO_AUTUMN_EQUINOX', 'XP_ASTRO.dll'
EXEC master..sp_addextendedproc 'XP_ASTRO_WINTER_SOLSTICE', 'XP_ASTRO.dll'
EXEC master..sp_addextendedproc 'XP_ASTRO_MOONPHASEK', 'XP_ASTRO.dll'
EXEC master..sp_addextendedproc 'XP_ASTRO_MOONPHASE', 'XP_ASTRO.dll'

To convert the current time expressed as a “datetime” data time to a Julian Day, we would use the following script:

DECLARE @curtime datetime
SELECT @curtime = GETDATE()
PRINT @curtime
DECLARE @Julian float
EXEC master..XP_ASTRO_DATE2JULIAN @curtime, @Julian OUTPUT
PRINT @Julian

And to perform the reverse conversion, we would use:

DECLARE @outcurtime datetime
EXEC master..XP_ASTRO_JULIAN2DATE @Julian, @outcurtime OUTPUT
PRINT @outcurtime

To calculate when the Spring Equinox occurs in the year 2004 expressed in both Dynamical Time and Universal Time, you would use the following script:

DECLARE @SpringEquinox float
EXEC master..XP_ASTRO_SPRING_EQUINOX 2004, @SpringEquinox OUTPUT
DECLARE @SpringEquinoxdt datetime
EXEC master..XP_ASTRO_JULIAN2DATE @SpringEquinox, @SpringEquinoxdt OUTPUT
PRINT 'Spring Equinox in 2004 (TD) ' + CAST(@SpringEquinoxdt AS varchar)
EXEC master..XP_ASTRO_DELTAT @SpringEquinox, @deltaT OUTPUT
SELECT @SpringEquinoxdt = DATEADD(second, -@deltaT, @SpringEquinoxdt)
PRINT 'Spring Equinox in 2004 (UT): ' + CAST(@SpringEquinoxdt AS varchar)

Finally to calculate when the New Moon of Mid-February 1977 occurs expressed in Dynamical Time, we would use the following:

DECLARE @MoonPhase float
SELECT @MoonPhaseK = -283.0
EXEC master..XP_ASTRO_MOONPHASE @MoonPhaseK, @MoonPhase OUTPUT
DECLARE @MoonPhasedt datetime
EXEC master..XP_ASTRO_JULIAN2DATE @MoonPhase, @MoonPhasedt OUTPUT
PRINT 'New Moon in February 1977 (TD) ' + CAST(@MoonPhasedt AS varchar)


The above book excerpt is from:

Super SQL Server Systems
Turbocharge Database Performance with C++ External Procedures

ISBN: 0-9761573-2-2
Joseph Gama, P. J. Naughter

 http://www.rampant-books.com/book_2005_2_sql_server_external_procedures.htm

 


 

 

 

Burleson Consulting Remote DB Administration


 

 


 

 

 

 

 
Burleson is the America's Team

Note: The pages on this site were created as a support and training reference for use by our staff of DBA consultants.  If you find it confusing, please exit this page.

Errata?  SQL Server technology is changing and we strive to update our SQL Server support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:and include the URL for the page.
 


Burleson Consulting
SQL Server database support

 

Copyright © 1996 -  2013 by Vaaltech Web Services. All rights reserved.

Hit Counter