Create synonym for function - sql

Would you prompt me, please, how to create synonym for function in SQL Server?
This method: CREATE SYNONYM cDateMin FOR server.db.[dbo].cDateMin
Doesn't help.
Script:
select dbo.cDateMin()
leads to the error:
Msg 4121, Level 16, State 1, Line 9
Cannot find either column "dbo" or the user-defined function or aggregate "dbo.cDateMin", or the name is ambiguous.
Script:
select cDateMin()
leads to the error:
Msg 195, Level 15, State 10, Line 9
'cDateMin' is not a recognized built-in function name.
Script:
select dbo.cDateMin
leads to the error:
Msg 4104, Level 16, State 1, Line 9
The multi-part identifier "dbo.cDateMin" could not be bound.
Script:
select cDateMin
leads to the error:
Msg 207, Level 16, State 1, Line 9
Invalid column name 'cDateMin'.
Guide from official source (to make a synonym by clicking the right button of the mouse on synonyms folder in SSMS (link) and creation the synonym 'by hand') created the same synonym and led tho the same errors.
Creation synonyms with the names different from the function name also didn't help.

Related

Create a table with SQL from Query result in SSMS

I am trying to create a new table from a query result in SSMS
I have tried:
CREATE TABLE table2 AS
(SELECT * FROM table1
WHERE code = 'x'
ORDER BY code;)
However I am getting an error telling me:
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'AS'.
Msg 156, Level 15, State 1, Line 8
Incorrect syntax near the keyword 'ORDER'.
Can anyone help?
Try this:
SELECT *
INTO NEW_TABLE
FROM table1
WHERE code = 'x'
ORDER BY code;

Getting NextVal from sequence in Visual Studio SQL Server

I am trying to insert into table using next value from sequence. This is causing an error in LocalDB of Visual Studio but works in SQL Developer.
insert into department (id_department, name, abbreviation, dept_head)
values (id_department_seq.nextval, 'School of Communications, Media, Arts and Design', department_abbreviation_seq.nextval, 'Nate Horowitz');
Getting this error
Msg 4104, Level 16, State 1, Line 63
The multi-part identifier "id_department_seq.nextval" could not be bound.
Msg 4104, Level 16, State 1, Line 63
The multi-part identifier "department_abbreviation_seq.nextval" could not be bound
That syntax for getting the next value for your sequence looks weird to me. I'm familiar with the following:
insert into department (id_department, name, abbreviation, dept_head)
values (
NEXT VALUE FOR id_department_seq,
'School of Communications, Media, Arts and Design',
NEXT VALUE FOR department_abbreviation_seq,
'Nate Horowitz'
);
Put this before your insert statement to ensure you have the sequence created.
if not exists(select * from sys.sequences where name ='id_department_seq') then
begin
create sequence id_department_seq start with 1000 increment by 1 minvalue 1000 maxvalue 99999;
end
insert into ....

Msg 102, Level 15, State 1, Line 1 Incorrect syntax near ')' while creating the table in sql

Whenever I try to create table in my selected database I get
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ')'
Can anybody tell me whats the error and how to overcome.
What's the error in it ?
CREATE TABLE first_name
(
)
The error is that every table needs to have at least a single column.
CREATE TABLE users
(
id int,
firstname varchar(255),
lastname varchar(255)
)

Understanding SSMS error messages, regarding an INSERT error:

When I run an SSMS command to insert data, I get this error:
Msg 206, Level 16, State 2, Line 1
Operand type clash: int is incompatible with ntext
What is ment by Level 16, State 2
My insert is a standard insert:
insert into surveys
values (18964, 'CD9E8ACE-0D22-4969-B324-620DAFF06F97', 19959, 486, etc etc
How do I find where my error was ?
Probably you are inserting value without single quote on a string column. String values need to be quoted as they are literal not identifiers.

Store Procedure Errors

I have created a stored procedure and am receiving these errors. How do I rectify this?
Msg 156, Level 15, State 1, Procedure usbinsertbookDatainto, Line 8
Incorrect syntax near the keyword 'AS'.
Msg 137, Level 15, State 2, Procedure usbinsertbookDatainto, Line 22
Must declare the scalar variable "#currentnoofcopiesavillable".
We would have to see the actual stored procedure SQL to be sure, but the errors are as follows:
Near the AS keyword, you have mistyped / have invalid syntax near Line 8
You have not DECLAREd #currentnoofcopiesavillable. Example being:
DECLARE #currentnoofcopiesavillable int;