sql server giving error : is not a recognized function name - sql

I created a backup of a database on sql server 200. I created a new database in sql server 2008 r2.
Now when i run a view i get the error :
'function_name' is not a recognized function name.
The function is there
And i can run it using
SELECT [dbo].[function_name] (
'hjh')
GO
SELECT dbo.function_name('kjk')
Why would this problem occur when it is functioning correctly originally?
EDIT:
I think it may be a security issue as schemas owned by the user under dbo does not contain antyhing?

Make sure you are executing it in the correct database context.
If the view is in Database2 and the function is in Database1 then you will need to fully qualify the function using the three part name:
Database1.dbo.[Function_Name]
All objects in a view are assumed to be in the same database as the view unless you specify otherwise.

Is the view on the same database as the function?
If they are not, you need to call it like [database_name].dbo.[function_name]

Related

Ignoring schema name on sql select?

using SQL server 2014 I am able to select without specifying the schema name when it is NOT DBO.
We are now switching over to SQL 2016 and I am no longer able to select without adding the schema name?
Problem: Going back into each stored proc to add the schema name in would take a lot of time so I was wondering if it is possible to ignore the schema name somehow? I have been searching google but haven't found anything..
The procs are used in our SSRS reports, which there are over 100 and some are embedded into the reports so if there is a way to avoid having to change each one that would be great!
It seems the default schema is a property of the connecting user. Maybe you should check how the new "migrated" user has been defined.

SQL Server Management Studio requiring full table path

Yesterday, in SQL Server Management Studio (SSMS) (v17.6) I could write and execute:
select * from MyTable;
Today, I now must write:
Select * from myDbName.dbo.MyTable;
However, the old syntax will recognize that the table is there and pull back the headers, but no content. Also, the intellisense with the older syntax.
Yet, in my VB code, I can still use the initial statement shown above.
Why? And, how do I change it back?
You are likely connected to another database on the instance. This commonly happens when the default database for the login isn't set to something explicitly. It defaults the the master database. You'll need to change it in the drop down for intellisense to pick up your table names, and for you to not have to fully qualify the server.database.schema.table.
Also, in the bottom right of your query window, make sure the query window which you are executing your query from is actually connected to the correct database. Since you aren't getting results back, I'd bet that you are also not connected to the correct database when you run your query, but an older or developmental database (where the data is different).

For a Front end access user interface connected to a backend SQL server, do I create new queries for tables in the SQL server or Access frontend?

I am a new database intern working with a access front end and SQL server backend database. The database was custom made for the company. One of my assignments is to take scripts and apply them to make four new tables. I am aware that I need to make a new query for each new table but I don't know if I should make the query in SQL server management studio or the frontend access program. I have tried copying and pasting the given scripts into a new query in access but I get an error message "invalid SQL statement expected 'DELETE', 'INSERT'...". I decided to try to break done the program a little bit and tested the first line
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id =OBJECT_ID(N'[dbo] .[FK_tblInstrumentInterfaceLog_tlkpInstrument]') AND parent_object_id = OBJECT_ID(N'[dbo].[tblInstrumentInterfaceLog]'))
but the same error message keeps popping up. I even tried just SELECT * FROM sys.foreign_keys, and I got the error message "could not find file...". I am very much a beginner and any guidance would be appreciated.Basically am I supposed to be applying these scripts the server SQL database or on the front end access program?
Are you using a pass-through query? i.e. not just a select query. Access needs to know where to send the query and since you are using TSQL not Access SQL this needs to be executed on the server.
Normally when you query a linked table the information of how to get the data (the connection string) is tied to the table. But for this kind of query you'll probably need to tell Access explicitly. Unless you are using an ADP/ADE, then the connection info travels with the program not the table.
As a general rule, you use SQL management studio (SSMS) to create and run those scripts. So the general accepted approach here is such scripts will not be placed in the front end. As noted such scripts if for some reason must be placed in the front end, then you have to create them as pass-though, but EVEN in this case you want to use the SSMS to create such quires.
So the answer here is you create the new scripts and make table queries in the back end, or in this case using the SQL server management studio.
The syntax checking, query editor etc. in recent versions of SSMS now has auto-complete etc. and you can test/write/update those scripts in SQL server. Once you have such a query or even several of them, then the resulting “several” statements can be pasted into a front end query that been created as pass-though. If you do not use a pass-though query, then you are creating and using and assuming client side SQL (JET (now called ACE)).
The client side has it own version of SQL syntax, and it is NOT 100% compatible with the SERVER SIDE. If you writing SQL in the client that is NOT pass though, then you using a linked table to SQL server. These linked tables thus will use local (JET/ACE) based SQL queries. The ODBC driver thus translates this SQL into server side compatible syntax. However the JET/ACE sql syntax is very limited when compared to SQL server and no server side commands exist in this SQL syntax for the client data engine (JET/ACE)
So for many quires, you will and can simply build such queries using the Access query builder.
However for SQL that needs to run 100% server side then such quires has to be setup as pass-though and are in most cased built + tested using SSMS.

SQL Server 2005 Linked server not finding tables

I have a linked server where I can clearly see all the databases and tables, so I know the server is properly linked. However, when I try to execute a query, it says invalid object name, at the linked server's table.
The linked server is aliased as TCS, therefore, my query takes that table as
FROM [TCS].dbo.table as b
I have also tried including the database name also as FROM [TCS\db1].dbo.table.
What am I missing here?
Try including the DB name like so:
FROM [TCS].db1.dbo.table as b
I don't think you can specify the DB using a slash.
I would also check to make sure your security settings for the linked server are allowing your account to connect. This article touches on how to do that.
either:
the user (used for the link) doesn't have access to the table; Grant access;
the default DB on the server doesn't have the table. You have to change it to the relevant one or included in the db in the name: [TCS].DATABASE.dbo.table as b;

Create View using Linked Server db in SQL Server

How can I create View on Linked Server db. For Example I have a linked server [1.2.3.4] on [5.6.7.8]. Both db servers are SQL Sserver 2005. I want to create View on [5.6.7.8] using table on linked server.
EDIT:
On creating using full name, [1.2.3.4].db.dbo.table, I am getting this error.
SQL Execution Error.
Executed SQL statement: SELECT * FROM 1.2.3.4.db.dbo.table (YOu can see brackets are not there.)
Error Source: .Net SqlClient Data Provider
Error Message: Incorrect syntax near '0.0'. ---> part of IP address.
I am just creating this in ManagementStudio, not using it because it is not created yet. I Have changed IP. In image you can see there are not brackets around IP but I given it and on error these brackets are removed.
Thanks.
You need to use the four part qualified name: linkedserver.database.schema.table
SELECT * FROM [1.2.3.4].Northwind.dbo.Customers
Here is an MSDN article about accessing object names.
You might want to try manually creating the view, rather than using the SQL Management tools:
CREATE VIEW [dbo].[sywx]
AS
SELECT *
FROM [1.2.3.4].Atia.dbo.IpPbxDCR
GO
I also recommend that you use a name, if possible, for the linked server rather than using the IP address.
Its a SQL Management Studio Issue.
If you try to create the view using management studio NEW VIEW then you get that error incorrect syntax.
But if you use SQL Query:
CREATE VIEW [dbo].[viewname]
AS
SELECT *
FROM [0.0.0.0].database.dbo.table
GO
then it will work.
To test you will see the view created when you refresh views.
If you just do a select query from the view you will see the view return results.
But if you try to go into design mode for that view and try executing the design query the error will pop up again even though the view was successfully created.
If the linked server is set up, you just reference tables on it using a four-part qualified name:
linkedserver.database.schema.table
So if your linked server name is [0.0.0.0], you can reference a table as:
[0.0.0.0].database.schema.table
your main problem is naming your Link Server with numbers (IP address). The only way that worked for me was using an alphabetical name for my Link Server without any dot '.'
You can use these lines of code to add your link server and authentication:
EXEC sp_addlinkedserver
#server='TEST_LINK',
#srvproduct='',
#provider='SQLNCLI',
#datasrc='tcp:0.0.0.0'
EXEC sp_addlinkedsrvlogin
#useself='FALSE',
#rmtsrvname='TEST_LINK',
#rmtuser='user',
#rmtpassword='secret'
You can find the original answer here
For linked servers using the periods for a web service name - this won't work.
The code details and steps of the difference is posted at:
http://www.access-programmers.co.uk/forums/showthread.php?t=260764
e.g. FROM [V2.EGG.COM]..[NAT_DBA].[NV_WELLS]
In SSMS 2008, the square brackets around the [V2.EGG.COM].. are removed by the editor. Then the update failes because it is more than 4 parts.
Have searched in vain to find a work-around.
The Script that does work is posted at the link above.
You can also just drag and drop the table/view object from the linked server into your view and Management Studio will create the four part reference for you.
You need to define a Linked Server before you can access it, since the linked server entry also contains the authentication details.
After creating a linked server, you can access its databases and their objects using the dot notation servername.database.[owner].object