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

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

Related

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

Can I create a view that will query a table from another sql server on another server but same domain

I need to query a table from another SQL Server on a different server but same domain, but I am not sure how I will be able to do it.
I tried solution given in this answer Can I create view in my database server from another database server but it doesn't work for me as I got SQL Server 2000 (please don't hate :-) ).
When I try solution given then i get this error,
Line 23: Incorrect syntax near '-'.
which is because command is not compatible with SQL Server 2000.
Edit
SELECT * FROM AnotherServer.AnotherServerDatabase.Server.Table1
you can link the servers and run cross server queries as long as you put the server name before the DB your running the query on.
For example
SELECT * FROM "linkedserver".dbo.aTable
(without "" marks )
bear in mind different server versions though. I run cross server queries from 2008 to 2000 servers and its a pain adapting :)

SQL Server 2008 R2 Linked Server to another SQL Server 200r R2 select query error Invalid data for type "Numeric"

we are having the following error message on a SQL Server 2008 R2 with SP1 linked server to another SQL Server 2008 R2 with SP2. The error message is: Invalid data for type "numeric" and is happening intermittently. It worked for couple months and re-appearing again. Called Microsoft Support last July 2012, they haven't able to solve it either and we closed the case after it mysteriously disappeared. All we did is just applied some Windows OS patches before the problem disappeared. Now the problem is re-appearing. The error message was from a simple query
select *
from Sales_LinkedServer].sales.dbo.temp_sales_detail
However, this table contains over 2 millions records. Tried and still failed using the
OPENQUERY:
Select *
From OPENQUERY ([Sales_LinkedServer],
'Select *
From Sales.dbo.temp_sales_detamil');
Also, this is happening on our production server but the similar Dev server has no problem at all.

Using SQL user defined function in MS Access 2007

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

Strange issue between sql server 2005 (32x) and sql server 2008 (64x) linked server

I have successfully created linked server between 2005 and 2008 version. We changed a table schema on 2008 and re ordered the table columns. We also did the same on 2005 server.
If we query both table in their own database then schema looks fine however
when I do
SELECT * FROM and Select * from then it is showing me old schema for 2008 table. Due to this my join and inserts are failing. Error "insert failed due to table column mismatch"
We restarted both the machines still not luck
Any idea ?
After some research I found answer on stack overflow it self :D
Column name or number of supplied values does not match table definition
Do drop #table and then select * INTO