| Author |
Topic |
|
Bren582
Starting Member
14 Posts |
Posted - 2008-01-25 : 09:12:51
|
| Guys,New to SQL and I'm trying to create a new field, entitled “Name” and see all employee names from my "Employee" table using the following format:LastName, FirstName, jobcode, emailaddress and hire date. after much effort my code is as follows:CREATE VIEW 'Name' AS SELECT LastName, FirstName, JobID, Email, Hiredate AS Relationship FROM 'Name'Create View 'Name' as Select LastName, FirstName, JobID, Email, Hiredate From EMPLOYEE Group By LastName, FirstName, JobID, Email, Hiredate Order By LastNameBut i'm still getting the following errors:Msg 111, Level 15, State 1, Line 196'CREATE VIEW' must be the first statement in a query batch.Msg 102, Level 15, State 1, Line 199Incorrect syntax near 'Name'.Msg 111, Level 15, State 1, Line 200'CREATE VIEW' must be the first statement in a query batch. Any assistance is greatly appreciated |
|
|
Bren582
Starting Member
14 Posts |
Posted - 2008-01-25 : 09:15:13
|
| Update,, I Realized I was duplicating my code.. Removed the duplicate and now I'm down to a single error. I would imagine there is a routine to prevent the first query error??Thanks for the assistance..Code:CREATE VIEW NamesAS SELECT LastName, FirstName, JobID, Email, Hiredate AS Relationship FROM NamesGroup By LastName, FirstName, JobID, Email, Hiredate Order By LastNameError:Msg 111, Level 15, State 1, Line 196'CREATE VIEW' must be the first statement in a query batch |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-25 : 09:34:11
|
| The error suggests you have some statements that preceeds the view definition.Remove it and rerun. |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2008-01-25 : 11:16:43
|
| After you sort that out, you are going to get an error regarding your ORDER BY clause. You can't ORDER BY in a view unless you also use a TOP or FOR XML clause.Jayto here knows when |
 |
|
|
Bren582
Starting Member
14 Posts |
Posted - 2008-01-25 : 12:05:54
|
| Guys, I'm not sure what you mean by "The error suggests you have some statements that preceeds the view definition.Remove it and rerun". I try running this as my first select query and receive the same error.. Please explain?? Thanks.. |
 |
|
|
Sara Karasik
Starting Member
10 Posts |
Posted - 2008-01-25 : 12:56:10
|
| Try to cut and paste it into a new Query window. |
 |
|
|
Bren582
Starting Member
14 Posts |
Posted - 2008-01-25 : 14:34:08
|
| Its runs OK in a fresh query window, I am also able to run in my program the following code error free on the main query but its not outputing the fields (LastName, FirstName, Email, Hiredate, JobID).. Any Ideas?? Thanks Guys..:GOIF OBJECT_ID ('Names') IS NOT NULLDROP VIEW Names ;GOCREATE VIEW NamesAS SELECT LastName, FirstName, Email, Hiredate, JobID FROM EMPLOYEE GROUP BY LastName, FirstName, Email, Hiredate, JobID; GO |
 |
|
|
|
|
|