November 19, 2015 at 7:48 am
CREATE VIEW [dbo].[test_view]
AS
INSERT INTO s_info
(
s_num, s_name
)
SELECT DISTINCT p_id, p_name
FROM unify
ERROR : Incorrect syntax near the keyword 'INSERT'.
Please help
November 19, 2015 at 7:51 am
Minnu (11/19/2015)
CREATE VIEW [dbo].[test_view]
AS
INSERT INTO s_info
(
s_num, s_name
)
SELECT DISTINCT p_id, p_name
FROM unify
ERROR : Incorrect syntax near the keyword 'INSERT'.
Please help
You can't do anything in a view except for a single SELECT (and all its capabilities).
What are you trying to do?
November 19, 2015 at 7:53 am
Minnu (11/19/2015)
CREATE VIEW [dbo].[test_view]
AS
SELECT DISTINCT p_id, p_name
FROM unify
ERROR : Incorrect syntax near the keyword 'INSERT'.
Please help
You cant use an the INSERT in a view.
You could do
CREATE VIEW [dbo].[test_view]
AS
SELECT DISTINCT p_id, p_name
FROM unify
GO
INSERT INTO s_info
(
s_num, s_name
)
SELECT p_id, p_name
FROM [dbo].[Test_view]
_________________________________________________________________________
SSC Guide to Posting and Best Practices
November 19, 2015 at 8:23 am
Thanks its working good.
also wants to delete from table before insert.
is it possible in this view...
November 19, 2015 at 8:37 am
Minnu (11/19/2015)
Thanks its working good.also wants to delete from table before insert.
is it possible in this view...
The insert is not part of the view, you might want to use a stored procedure.
CREATE PROCEDURE [dbo].[test_procedure]
AS
DELETE FROM s_info;
--WHERE ?
INSERT INTO s_info
(
s_num,
s_name
)
SELECT DISTINCT
p_id,
p_name
FROM unify;
GO
November 19, 2015 at 8:45 am
I don't mean this as a slam. It's a recommendation. This is some pretty basic stuff that you're talking about and, if your job requires you to work with T-SQL, I strongly recommend that you get some training. Ask the folks at work. "The answer is always 'No' unless you ask".
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply