Using SQL user defined function in MS Access 2007 - sql

I am very new to Access and need a bit help over here.
I was working on MS Access 2007 (in VB) with SQL 2008 Server as my database.
I wanted to show a SQL table in the frontend of Access but faced the problem while using SQL user defined function with my SQL query in Access 2007. I wrote this function and the query in SQL Query design of Access and tried to Run it.. but its showing error (Userdefined "timepart" function not recognized) !!
CREATE function dbo.timepart (#date as SMALLDATETIME)
RETURNS SMALLDATETIME
AS
BEGIN
RETURN #date - DATEADD(d, DATEDIFF(d,0,#date), 0)
END
SELECT * FROM TABLENAME WHERE dbo.timepart(FIELDNAME) Between '9:30' AND '17:30';
I guess MS Access doesn't allow to write UDF SQL functions! I tried this same query in my local SQL Server 2008 database (SQL management studio) and is working perfectly fine.

You should create a pass-through query. With a pass-through query, the code is run on SQL Server and the results are returned to MS Access. You can therefore use SQL Server T-SQL.
Also access-SQL pass-through query (creating SP) error

Related

SQL Query not working properly after migrating to Sql Express from sql server 2008

I was working on a database in sql server 2008 and all my queries were working but now we have shifted the database to sql express 2012.
Now some of my queries are working whereas some are throwing error
Example:
SELECT DATEPART(HOUR,TIME_OF_DAY) FROM dbname.T1
Query1 error: Cannot convert string to datetime.
Now if I select * from dbname.T1 and replace the * with DATEPART(HOUR,TIME_OF_DAY) it is working.
The only difference is Initially it is using SQLEXPRESS.dbname and when it runs it is using SQLEXPRESS.master
I don't understand why this is happening. Thanks in advance

Query Syntax for linked sql server

please help: I'm new to linked servers & in MS SQL I have successfully added one (from an MS Access file) as shown:
I'm having trouble querying this database here. What is the syntax? Thanks.
Okay, by simply using Management Studio in MS SQL I ran a SELECT query on the table through "Script Table as" (right-click) and with query results I was sure that this then is the format:
SELECT * FROM [RXPIPEDB]...[product]
Furthermore, I can run updates using this syntax:
UPDATE [RXPIPEDB]...[Product]
SET X = ..something..
Of-course for the UPDATE query, you must have set your LINKED SERVER properties > Server Options "RPC" & "RPC out" to TRUE.
Thank you all.
The query its OK. U have a problem in the configuration of linked server.
Check this: Run a Query from Linked Server (Oracle) in SQL Server2008 R2

Equivalent T-SQL to Microsoft Access

I am trying to replicate my T-SQL script written in Microsoft SQL Server Management Studio to Microsoft Access Query Design.
I have pretty much figured out most of the script except the following;
convert(char, 'Approved') as status
or rather
status = 'Approved'
How would i write any of those two into Microsoft Access SQL Designer?

Query works in SQL Developer but not in a pass through query in Access

I want to extract data from an Oracle 11g R2 database and import it in a table in Ms Access 2007.
I have a query that looks like :
SELECT * FROM aPublicSynonym
on the Oracle db using a READONLY user and it works fine in Oracle SQL Developer.But when I execute it as a pass-through query in ms Access I get:
[Oracle][ODBC][Ora] Ora-00942: table/view does not exist(#942)
I use the same ODBC data source with both sql developer and access and when I query in access :
select sys_context( 'userenv', 'current_schema' ) from dual;
It works and returns the same user schema as in sql developer.
Can someone give me a hint about why i don't seem to have the privilege to access the public synonym when connecting with Access?
Thanks

SQL Limitations of Microsoft Query in Excel

I have using Microsoft Query in Excel 2007 for the past few weeks and have had many cases where the query works fine in SQL Server 2005 but gives irrelevant errors in Microsoft Query. For example I have this case Multipart identifier error in Excel 2007 MS Query but not in SQL Server 2008 where when I removed the sub queries in SELECT and joined those tables it worked. It doesn't seem to work in this case too.
Pass parameters to temp variables in MS Query on SQL Server from Excel I guess CTEs don't work in MS Query like CTE in MS Query Excel 2007. It doesn't work in this case too. Alternative to Left Join
Can anyone list all the SQL Limitations in Microsoft Query?
I often found that queries that run on Oracle, AS400 and MS Sql wouldn't run on MS Query, I think the reason is because that MS Query always tries to display the query graphically. If the query is impossible to show graphically MS Query will display a waning message and then display just results (not the table or conditional panes). Simple queries work fine but there is a middle ground between complex and simple that MS Query seems to choke on.
The solution I found was not to simplify my queries, but to actually make them more complex thus forcing MS Query not to attempt a graphical display. I did this by making my queries a sub query and entering into MS Query like so:
SELECT * FROM (
--enter your query here
) a