Sunday 21 October 2007

Migrating data from SPSS to SQL Server 2005

SQL Server 2005 has among Native SQL Server also OLEDB connection which enables you to import data to you favorite SPSS version.

Using SPSS Syntax you can with almost no haste import data - using T-Sql Query to SPSS.

[Code]

*sql->spss.

get data

/type=odbc
/connect='Driver={SQLServer};Server=My_server_name;Uid=My_User_name;Pwd=My_password;database=My_database'

/sql ='select id, name, cast(round(cast(datediff(day, BirthDate, getdate()) as float) / 365.25, 0, -1) as integer),(select max(date_time) from table1 where table1.date = date2) as Another_Date from table2 as t2 join table3 as t3 on t2.id = t3.id join table4 as t4 on t2.date = t4.id where t4.my_number = 1'
cache.

[/Code]


Where parameters My_server_name, My_username, My_password and My_database should be replaced.


SQL query should be enclosed in single aphostrophe ' and your SQL query should not contain any single quotes for enabling strings (eg.: where name = 'John').