PSQL / PgAdmin query issue - sql

Learning Sql, this query returns a syntax error in Pgadmin and Sql shell says there are more entries than target yet there are 8 entries for 8 columns in my table. I've tried specifying the target columns as i've read its good practice to no avail. I'm going off of a course for this, its another random exercise, but the course is frankly useless mixes commands for psql oracle or straight up incorrect ones, basically nothing in it works as it describes. While i'm used to it can't say it helps and leaves me stuck on what's overwhelmingly likely basic syntax written wrong.
Ty for your time.
INSERT INTO EMP(noemp, nomemp, emploi, mgr, dateemb, sal, comm, nodept)
VALUES (
(7369, 'SERGE', 'FONCTIONNAIRE', 7902, TO_DATE('17-DEC-1980', 'DD-MON-YYYY'), 800, NULL, 20),
(7499, 'BRAHIM', 'VENDEUR', 7698, TO_DATE('20-FEB-1981', 'DD-MON-YYYY'), 1600, 300, 30),
(7521, 'NASSIMA', 'VENDEUR', 7698, TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 1250, 500, 30),
(7566, 'LUCIE', 'GESTIONNAIRE', 7839, TO_DATE('12-APR-1981', 'DD-MON-YYYY'), 2975, NULL, 20),
(7654, 'MARTIN', 'VENDEUR', 7698, TO_DATE('28-SEP-1981', 'DD-MON-YYYY'), 1250, 1400, 30),
(7698, 'BENJAMIN', 'GESTIONNAIRE', 7839, TO_DATE('01-MAY-1981', 'DD-MON-YYYY'), 2850, NULL, 30),
(7782, 'DAYANE', 'GESTIONNAIRE', 7839, TO_DATE('09-JUNE-1981', 'DD-MON-YYYY'), 2450, NULL, 10),
(7788, 'ARIJ', 'ANALYSTE', 7566, TO_DATE('09-DEC-1982', 'DD-MON-YYYY'), 3050, NULL, 20),
(7839, 'MAYAR', 'PRESIDENT', NULL, TO_DATE('17-NOV-1981', 'DD-MON-YYYY'), 5000, NULL, 10),
(7844, 'ROI', 'VENDEUR', 7698, TO_DATE('08-SEP-1981', 'DD-MON-YYYY'), 1500, 0, 30),
(7876, 'VIRGINIE', 'FONCTIONNAIRE', 7788, TO_DATE('12-JAN-1983', 'DD-MON-YYYY'), 1100, NULL, 20),
(7900, 'LYNA', 'FONCTIONNAIRE', 7698, TO_DATE('03-DEC-1981', 'DD-MON-YYYY'), 950, NULL, 30),
(7902, 'ASMA', 'ANALYSTE', 7566, TO_DATE('03-DEC-1981', 'DD-MON-YYYY'), 3000, NULL, 20),
(7934, 'SIMONE', 'FONCTIONNAIRE', 7782, TO_DATE('23-JAN-1982', 'DD-MON-YYYY'), 1300, NULL, 10)
);
Edit: Adding parenthseses (which i add at some point, cf below gets) rid of line 4 error and returns line 11 error instead, same text.
Edit2: TLdr there was a typo on one month and lacked proper formatting. Ty all.

I found a french month name in your SQL Code (JUIN) :
7782, ’DAYANE’, ’GESTIONNAIRE’, 7839, TO_DATE(’9-**JUIN**-1981', ’DD-MON-YYYY’), 2450, NULL, 10,
it must be remplaced by 'JUNE'.
Try to put each record between parenthesis like that :
INSERT INTO EMP(noemp, nomemp, emploi, mgr, dateemb, sal, comm, nodept)
VALUES (7369, 'SERGE', 'FONCTIONNAIRE', 7902, TO_DATE('17-DEC-1980', 'DD-MON-YYYY'), 800, NULL, 20),
(7499, 'BRAHIM', 'VENDEUR', 7698, TO_DATE('20-FEB-1981', 'DD-MON-YYYY'), 1600, 300, 30),
(7521, 'NASSIMA', 'VENDEUR', 7698, TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 1250, 500, 30),
(7566, 'LUCIE', 'GESTIONNAIRE', 7839, TO_DATE('12-APR-1981', 'DD-MON-YYYY'), 2975, NULL, 20),
(7654, 'MARTIN', 'VENDEUR', 7698, TO_DATE('28-SEP-1981', 'DD-MON-YYYY'), 1250, 1400, 30),
(7698, 'BENJAMIN', 'GESTIONNAIRE', 7839, TO_DATE('01-MAY-1981', 'DD-MON-YYYY'), 2850, NULL, 30),
(7782, 'DAYANE', 'GESTIONNAIRE', 7839, TO_DATE('9-JUNE-1981', 'DD-MON-YYYY'), 2450, NULL, 10),
(7788, 'ARIJ', 'ANALYSTE', 7566, TO_DATE('09-DEC-1982', 'DD-MON-YYYY'), 3050, NULL, 20),
(7839, 'MAYAR', 'PRESIDENT', NULL, TO_DATE('17-NOV-1981', 'DD-MON-YYYY'), 5000, NULL, 10),
(7844, 'ROI', 'VENDEUR', 7698, TO_DATE('08-SEP-1981', 'DD-MON-YYYY'), 1500, 0, 30),
(7876, 'VIRGINIE', 'FONCTIONNAIRE', 7788, TO_DATE('12-JAN-1983', 'DD-MON-YYYY'), 1100, NULL, 20),
(7900, 'LYNA', 'FONCTIONNAIRE', 7698, TO_DATE('03-DEC-1981', 'DD-MON-YYYY'), 950, NULL, 30),
(7902, 'ASMA', 'ANALYSTE', 7566, TO_DATE('03-DEC-1981', 'DD-MON-YYYY'), 3000, NULL, 20),
(7934, 'SIMONE', 'FONCTIONNAIRE', 7782, TO_DATE('23-JAN-1982', 'DD-MON-YYYY'), 1300, NULL, 10)
You can verify it with this link

Related

Why is my sql script returning "[null]" and "0" values even though my table is populated?

I have manually populated a table as follows:
INSERT INTO country VALUES
-- columns are countryid, name, continent, population, gdp, lifeexpectancy, founded
(1, 'Argentina', 36.3, 348.2, 70.75, 9/7/1816),
(2, 'Brazil', 183.3, 1004, 65.6, 9/7/1822),
(3, 'Canada', 30.1, 658, 77.08, 1/7/1867),
(4, 'England', 60.8, 1256, 75.15, NULL),
(5, 'France', 60, 1000, 75.15, 14/7/1789),
(6, 'Mexico', 107.5, 694.3, 69.36, 16/9/1821),
(7, 'USA', 270, 8003, 75.75, 4/7/1776),
(8, 'Cuba', 11.7, 16.9, 75.95, 24/2/1895),
(9, 'Guatemala', 20, 200, 60, 15/9/1821),
(10, 'Tanzania', 55.57, 47.43, 60.76, 9/12/1961),
(11, 'India', 1324, 2264, 68.35, NULL),
(12, 'South Africa', 55.91, 294.8, 57.44, 31/05/1910),
(13, 'Costa Rica', 4.86, 57.44, 79.59, 15/9/1821),
(14, 'Uganda', 41.49, 25.53, 59.18, NULL);
but when I query
SELECT lifeexpectancy FROM country;
The tables returns a combination of "0" and "[null]" values.
I've tried changing the data_type of lifeexpectancy. Neither text nor numeric data types return values that have been entered.
Any suggestions?
You are not inserting the continent. Presumably you want that, but it is not in your sample data.
You should be using standard date formats. In most databases, YYYY-MM-DD works. And you should list the columns. So:
INSERT INTO country (countryid, name, population, gdp, lifeexpectancy, founded)
VALUES (1, 'Argentina', 36.3, 348.2, 70.75, '1816-07-09'),
(2, 'Brazil', 183.3, 1004, 65.6, '1822-07-09'),
(3, 'Canada', 30.1, 658, 77.08, '1867-07-01'),
(4, 'England', 60.8, 1256, 75.15, NULL),
(5, 'France', 60, 1000, 75.15, '1789-07-14'),
(6, 'Mexico', 107.5, 694.3, 69.36, '1821-09-16'),
(7, 'USA', 270, 8003, 75.75, '1776-07-04'),
(8, 'Cuba', 11.7, 16.9, 75.95, '1895-02-24'),
(9, 'Guatemala', 20, 200, 60, '1821-09-15'),
(10, 'Tanzania', 55.57, 47.43, 60.76, '1961-12-09'),
(11, 'India', 1324, 2264, 68.35, NULL),
(12, 'South Africa', 55.91, 294.8, 57.44, '1910-05-31'),
(13, 'Costa Rica', 4.86, 57.44, 79.59, '1821-09-15'),
(14, 'Uganda', 41.49, 25.53, 59.18, NULL);
I believe you're supplying 6 values instead of 7 (may be because of Auto Increment), if that the case you need to specify the columns here.
Also pass date with single quotes surrounded:
INSERT INTO country (countryid, name, continent, population, gdp, lifeexpectancy, founded)
VALUES
(1, 'Argentina', 36.3, 348.2, 70.75, '9/7/1816'),
(2, 'Brazil', 183.3, 1004, 65.6, '9/7/1822'),
(3, 'Canada', 30.1, 658, 77.08, '1/7/1867'),
(4, 'England', 60.8, 1256, 75.15, NULL),
(5, 'France', 60, 1000, 75.15, '14/7/1789'),
(6, 'Mexico', 107.5, 694.3, 69.36, '16/9/1821'),
(7, 'USA', 270, 8003, 75.75, '4/7/1776'),
(8, 'Cuba', 11.7, 16.9, 75.95, '24/2/1895'),
(9, 'Guatemala', 20, 200, 60, '15/9/1821'),
(10, 'Tanzania', 55.57, 47.43, 60.76, '9/12/1961'),
(11, 'India', 1324, 2264, 68.35, NULL),
(12, 'South Africa', 55.91, 294.8, 57.44, '31/05/1910'),
(13, 'Costa Rica', 4.86, 57.44, 79.59, '15/9/1821'),
(14, 'Uganda', 41.49, 25.53, 59.18, NULL);

Getting result from select command [SQL]

This is my table:
INSERT INTO Emp (EmpNo, EName, Job, Mgr, HireDate, Sal, Comm, DeptNo)
VALUES (7369, 'SMITH', 'CLERK', 7902, '1980-12-17', 800, NULL, 20),
(7499, 'ALLEN', 'SALESMAN', 7698, '1981-02-20', 1600, 300, 30),
(7521, 'WARD', 'SALESMAN', 7698, '1981-02-22', 1250, 500, 30),
(7566, 'JONES', 'MANAGER', 7839, '1981-04-02', 2975, NULL, 20),
(7654, 'MARTIN', 'SALESMAN', 7698, '1981-09-28', 1250, 1400, 30),
(7698, 'BLAKE', 'MANAGER', 7839, '1981-05-01', 2850, NULL, 30),
(7782, 'CLARK', 'MANAGER', 7839, '1981-06-09', 2450, NULL, 10),
(7788, 'SCOTT', 'ANALYST', 7566, '1987-04-19', 3000, NULL, 20),
(7839, 'KING', 'PRESIDENT', NULL, '1981-11-17', 5000, NULL, 10),
(7844, 'TURNER', 'SALESMAN', 7698, '1981-09-08', 1500, 0, 30),
(7876, 'ADAMS', 'CLERK', 7788, '1987-05-23', 1100, NULL, 20),
(7900, 'JAMES', 'CLERK', 7698, '1981-12-03', 950,NULL, 30),
(7902, 'FORD', 'ANALYST', 7566, '1981-12-03', 3000, NULL, 20),
(7934, 'MILLER', 'CLERK', 7782, '1982-01-23', 1300, NULL, 10);
Now I want to get every worker who their job isn't PRESIDENT or MANAGER.
This is my command:
SELECT *
FROM [dbo].EMP
WHERE NOT Job = 'MANAGER' OR Job = 'PRESIDENT';
The result is almost correct, but I get one PRESIDENT who shouldn't be there.
This one:
7839 KING PRESIDENT NULL 1981-11-17 5000.00 NULL 10
You need to wrap it with brackets:
SELECT * FROM [dbo].EMP WHERE NOT (Job='MANAGER' OR Job='PRESIDENT');
Or use NOT IN:
SELECT * FROM [dbo].EMP WHERE Job NOT IN ('MANAGER', 'PRESIDENT');
Use NOT IN
SELECT * FROM [dbo].EMP WHERE Job NOT in ('MANAGER' ,'PRESIDENT')

Deriving the first instance of a specific node type in a tree structure query using SQL

I am designing an Electrical design software that will model an electrical utility system from the incoming Power Utility right down to the individual circuits such as computers and coffee machines.
I want to give each component of the system a dedicated table. eg. Transformers, Loads, cables, PowerPanels (called buses in this example).
Each component can be connected to one or many other components. I am using a parent/child table to manage the connections and plan to use a CTE to derive the hierarchical tree structure for a given component.
The voltage supplying any component in the system will be derived by finding the first instance of a transformer or a utility in the tree.
I have developed a query that can handle this as demonstrated below.
However, this only works for selecting one component in the CTE. I am looking for a way to select all buses and their connected voltage (nearest trafo or Utility). The only solution I can come up with is to use a table function on the above query. Is there a better way of doing this.
CREATE TABLE #componentConnection
(componentConnectionID int, parentComponentID varchar(4), childComponentID int)
;
INSERT INTO #componentConnection
(componentConnectionID, parentComponentID, childComponentID)
VALUES
(1, '13', 18),
(2, '13', 19),
(3, '13', 20),
(4, '13', 21),
(5, '13', 22),
(6, '13', 23),
(7, '14', 24),
(8, '14', 25),
(9, '14', 26),
(10, '14', 27),
(11, '14', 28),
(12, '14', 29),
(13, '15', 30),
(14, '15', 31),
(15, '15', 32),
(16, '15', 33),
(17, '15', 34),
(18, '15', 35),
(19, '16', 36),
(20, '16', 37),
(21, '16', 38),
(22, '16', 39),
(23, '16', 40),
(24, '16', 41),
(25, '1', 5),
(27, '5', 13),
(28, NULL, 1),
(29, '18', 6),
(30, '6', 11),
(31, '11', 7),
(32, '7', 14)
;
CREATE TABLE #component
(componentID int, componentName varchar(8), componentType varchar(7))
;
INSERT INTO #component
(componentID, componentName, componentType)
VALUES
(1, 'Utility1', 'utility'),
(2, 'Utility2', 'utility'),
(3, 'utility3', 'utility'),
(4, 'utility4', 'utility'),
(5, 'Cable1', 'cable'),
(6, 'Cable2', 'cable'),
(7, 'Cable3', 'cable'),
(8, 'Cable4', 'cable'),
(9, 'Cable5', 'cable'),
(10, 'Cable6', 'cable'),
(11, 'Trafo1', 'trafo'),
(12, 'Trafo2', 'trafo'),
(13, 'Bus1', 'bus'),
(14, 'Bus2', 'bus'),
(15, 'Bus3', 'bus'),
(16, 'Bus4', 'bus'),
(17, 'Bus5', 'bus'),
(18, 'cub1', 'cir'),
(19, 'cub2', 'cir'),
(20, 'cub3', 'cir'),
(21, 'cub4', 'cir'),
(22, 'cub5', 'cir'),
(23, 'cub6', 'cir'),
(24, 'cub1', 'cir'),
(25, 'cub2', 'cir'),
(26, 'cub3', 'cir'),
(27, 'cub4', 'cir'),
(28, 'cub5', 'cir'),
(29, 'cub6', 'cir'),
(30, 'cub1', 'cir'),
(31, 'cub2', 'cir'),
(32, 'cub3', 'cir'),
(33, 'cub4', 'cir'),
(34, 'cub5', 'cir'),
(35, 'cub6', 'cir'),
(36, 'cub1', 'cir'),
(37, 'cub2', 'cir'),
(38, 'cub3', 'cir'),
(39, 'cub4', 'cir'),
(40, 'cub5', 'cir'),
(41, 'cub6', 'cir')
;
CREATE TABLE #utility
([utilityID] int, [componentID] int, [utlityKV] float)
;
INSERT INTO #utility
([utilityID], [componentID], [utlityKV])
VALUES
(1, 1, 0.4),
(2, 2, 0.208),
(4, 3, 0.48),
(5, 4, 0.208)
;
CREATE TABLE #transformer
([transformerID] int, [componentID] int, [facilityID] int, [transformerName] varchar(4), [transformerPrimaryTapKv] float, [transformerSecondaryTapKv] float, [transformerPrimaryKv] float, [transformerSecondaryKv] float)
;
INSERT INTO #transformer
([transformerID], [componentID], [facilityID], [transformerName], [transformerPrimaryTapKv], [transformerSecondaryTapKv], [transformerPrimaryKv], [transformerSecondaryKv])
VALUES
(3, 11, 1, NULL, 0.48, 0.208, 0.48, 0.208),
(4, 12, 2, NULL, 0.48, 0.4, 0.48, 0.4)
;
CREATE TABLE #Bus
([busID] int, [busTypeID] int, [componentID] int, [bayID] int, [busName] varchar(4), [busConductorType] varchar(6), [busRatedCurrent] int)
;
INSERT INTO #Bus
([busID], [busTypeID], [componentID], [bayID], [busName], [busConductorType], [busRatedCurrent])
VALUES
(8, 1, 13, 1, 'bus1', 'Copper', 60),
(9, 1, 14, 1, 'bus2', 'copper', 50),
(10, 2, 15, 1, 'bus3', 'copper', 35),
(11, 2, 16, 1, 'bus4', 'copper', 35),
(13, 1, 17, 1, 'bus5', 'copper', 50)
;
WITH CTE AS (SELECT childComponentID AS SourceID, childComponentID, 0 AS depth
FROM #ComponentConnection
UNION ALL
SELECT C1.SourceID, C.childComponentID, c1.depth + 1 AS depth
FROM #ComponentConnection AS C INNER JOIN
CTE AS C1 ON C.parentComponentID = C1.childComponentID)
SELECT childComponentID,b.busName, min(depth)
--,c.componentType
,isnull(t.transformerSecondaryKv,u.utlityKV) kV
FROM CTE AS CTE1
join #Component c
on CTE1.SourceID = c.componentID
left join #Utility u
on CTE1.SourceID = u.componentID
left join #Transformer t
on CTE1.SourceID = t.componentID
LEFT JOIN #Bus b
on cte1.childComponentID = b.componentID
where busName is not null and c.componentType in ('Utility','trafo')
group by childComponentID,b.busName,isnull(t.transformerSecondaryKv,u.utlityKV)
order by depth
The desired result would be as follows for a Bus. I want to list all Buses and their associated Voltage. I would select all from the Bus table and derive the voltage from the heirarchical structure
Result
BusName | Voltage
Bus 1 | 0.4
Bus 2 | 0.208
Bus 3 | etc

nested select TOP 1 statement

I am working on a system currently for Asset Management within our company.
The system allows users to sign in/out items on either a permenant or temporary basis.
I am working on some reporting on the system and have hit a stumbling block with returning the relevent data.
So i know that i need a nested Select TOP 1 statement within my main query but i cant get it to work.
The main query is as follows:
SELECT [Asset-User].ID, [Asset-User].Asset_ID, [Assets].ID, [Assets].Signed_Out, [Assets].Asset_Tag_Serial_Num, [Assets].Name_Hostname, [Assets].Type_ID, [Asset_Type].ID, [Asset_Type].Name_Model, [Asset-User].User_ID, [Company_Users].ID, [Asset-User].Sign_Out_Date, [Asset-User].Return_Date, [Asset-User].[Perm_Signout?]
FROM [Asset-User], [Assets], [Asset_Type], [Company_Users]
WHERE ([User_ID] = '1') AND [Asset-User].Asset_ID = [Assets].ID AND [Assets].Type_ID = [Asset_Type].ID AND [Asset-User].User_ID = [Company_Users].ID AND [Assets].Signed_Out = '1'
So this query returns everything that is currently marked as "Signed Out" that has ever been signed out by User 1.
Somewhere in here i need to add a nested Select TOP 1 on Asset-User.ID so that it only returns items that are marked as permanent sign outs, OR if not permanent that they have most recently been signed out by User 1.
This would then only give me a list of items currently assigned to that user and not display the Asset if someone else has signed it out since
Any help would be greatly appreciated
As per request Sample data below:
https://docs.google.com/spreadsheets/d/1o4T6bsxyO-1dGE0-FUtWFboRupcq4o4V9i2Em0_BjyU/edit?usp=sharing
First sheet shows actual results, second sheet shows roughly what should be expected
As you will see here, this user has signed out a few items multiple times (and those items may not most recently have been signed out by this user)
Its hard to get the sample data but in essence there should be no duplicate Asset_ID's in the list as only the most recent ID (sign out ID this relates to) should be displayed for each Asset_ID.
Does that help?
Thanks again
As per request here is the Schema build code that will create a sample DB to work with
CREATE TABLE Asset_Type
([ID] int, [Global_ID] int, [Name_Model] varchar(30), [Description_Spec] varchar(54))
;
INSERT INTO Asset_Type
([ID], [Global_ID], [Name_Model], [Description_Spec])
VALUES
(1, 1, 'Dell Optiplex 3020', 'Windows 7 Professional, Intel Core i3 3.40GHz,4Gb RAM'),
(2, 3, 'Viewsonic VA2231wa', 'Viewsonic Widescreen Monitor'),
(3, 3, 'Samsung S24B150BL', 'Samsung LED 24" Widescreen Monitor')
;
CREATE TABLE Assets
([ID] int, [Asset_Tag_Serial_Num] varchar(29), [Type_ID] int, [Purchase_Date] varchar(10), [Purchase_Price] varchar(7), [Name_Hostname] varchar(36), [Signed_Out] int)
;
INSERT INTO Assets
([ID], [Asset_Tag_Serial_Num], [Type_ID], [Purchase_Date], [Purchase_Price], [Name_Hostname], [Signed_Out])
VALUES
(1, '0206', 1, '2013-11-29', '323.30', 'WS0206', 1),
(3, '0226', 2, NULL, NULL, 'Viewsonic VA2231wa - 0226', 1),
(4, '0204', 1, '2013-11-29', '323.00', 'WS0204', 1),
(5, '0205', 1, '2013-11-29', '323.00', 'WS0205', 1),
(6, '0108', 1003, NULL, NULL, 'Small Office Sat Nav', 1),
(7, '0092', 1004, NULL, NULL, 'Large Office Sat Nav', 1),
(8, 'GWC36-DHDBC-J2MXY-H2BGY-8C79G', 1005, '1900-01-01', '0.00', 'MS Office for WS0020', 1),
(9, '0020', 1006, '1900-01-01', '0.00', 'WS0020', 1),
(10, '0173', 2, '1900-01-01', '0.00', 'Viewsonic VA2231wa - 0173', 1),
(11, '0172', 1007, '1900-01-01', '0.00', 'Dell 19" Monitor 0172', 1),
(12, '00104926EC6B', 1008, '1900-01-01', '0.00', 'Shortel 230 - EC6B', 1),
(13, '0227', 1009, NULL, NULL, 'Blue - Yeti Mic', 0),
(14, '0221', 1, NULL, NULL, 'WS0221', 1),
(15, '0222', 1, '2013-11-29', '323.00', 'WS0222', 1),
(16, '0223', 1, NULL, NULL, 'WS0223', 1),
(17, '0220', 1, '2013-11-29', '323.00', 'WS0220', 1),
(18, '0217', 1, '2013-11-29', '323.00', 'WS0217', 1),
(19, '0218', 1, NULL, NULL, 'WS0218', 1),
(20, '0219', 1, '2013-11-29', '323.00', 'WS0219', 1),
(21, '0228', 2, NULL, NULL, 'Viewsonic VA2231wa - 0228', 1),
(22, '0229', 1010, NULL, NULL, 'Dell 19" Monitor 0229', 1),
(23, '00104931AA16', 1011, NULL, NULL, 'Shortel 115 - AA16', 1),
(24, '0093 - DYTJ18X4DJ8T', 1012, NULL, NULL, 'Office IPad 3', 1),
(25, '0095', 1013, '1900-01-01', '0.00', '320Gb External HDD', 1),
(26, '0071', 1014, NULL, NULL, '0071 - NEC Projector', 0),
(27, '0072', 1015, NULL, NULL, '0072 - Black Dell Projector', 0),
(28, '0073', 1016, '1900-01-01', '0.00', '0073 - Dell Projector', 0),
(29, '0230', 1017, '1900-01-01', '0.00', '0230 - Silver Dell Projector', 0),
(30, '0064', 1018, NULL, NULL, 'WS0064', 0),
(31, '0231', 1019, NULL, NULL, 'Freecom 1GB Pen - 0231', 1),
(47, '0165', 2, NULL, NULL, 'Viewsonic VA2231wa - 0165', 1),
(48, '0232', 1010, '1900-01-01', '0.00', 'Dell 19" Monitor 0232', 1),
(49, '0233', 1010, '1900-01-01', '0.00', 'Dell 19" Monitor 0233', 1),
(50, '0137', 1022, NULL, NULL, 'Viewsonic VA2248-LED - 0137', 1),
(51, '0234', 1010, '1900-01-01', '0.00', 'Dell 19" Monitor 0234', 1),
(52, '0235', 1010, '1900-01-01', '0.00', 'Dell 19" Monitor 0235', 1),
(53, '0134', 1010, NULL, NULL, 'Dell 19" Monitor 0134', 0),
(54, '0135', 1022, NULL, NULL, 'Viewsonic VA2248-LED - 0135', 1),
(55, '0236', 3, '1900-01-01', '0.00', 'Samsung S24B150BL - 0236', 1),
(56, '001049201D9A', 1008, '1900-01-01', '0.00', 'Shortel 230 - 1D9A', 1),
(57, '0010492015AE', 1008, '1900-01-01', '0.00', 'Shortel 230 - 15AE', 1),
(93, '0269', 1029, '1900-01-01', '0.00', 'TP-Link Switch - 0269', 0),
(94, '0058', 1030, NULL, NULL, 'WS0058', 1),
(95, '0270', 1031, NULL, NULL, 'MeetingRoom3', 1),
(96, '0243', 1032, NULL, NULL, 'MeetingRoom2', 1),
(97, '0271', 1027, NULL, NULL, 'Dynamode SW80010-D Switch - 0271', 0),
(123, '0281', 1045, '2014-07-18', '104.50', 'Philips 23.6" Monitor 0281', 0),
(124, '0282', 1045, '2014-07-18', '104.50', 'Philips 23.6" Monitor 0282', 1),
(125, '0283', 1045, '2014-07-18', '104.50', 'Philips 23.6" Monitor 0283', 0),
(126, '0284', 1045, '2014-07-18', '104.50', 'Philips 23.6" Monitor 0284', 1),
(127, '0285', 1045, '2014-07-18', '104.50', 'Philips 23.6" Monitor 0285', 1),
(128, '0286', 1045, '2014-07-18', '104.50', 'Philips 23.6" Monitor 0286', 1),
(129, '0287', 1045, '2014-07-18', '104.50', 'Philips 23.6" Monitor 0287', 1),
(143, '0280', 1, '2014-07-03', '403.80', 'WS0280', 1),
(144, '0296', 1, '2014-07-03', '403.80', 'WS0296', 1),
(145, '0297', 1, '2014-07-03', '403.80', 'WS0297', 1),
(146, '0298', 1, '2014-07-03', '403.80', 'WS0298', 1),
(147, '0299', 1, '2014-07-03', '403.80', 'WS0299', 1),
(148, '0052', 1036, '1900-01-01', '0.00', 'WS0052', 1),
(168, '0312', 1047, NULL, NULL, 'Epson White HD - 0312', 1),
(169, '0201', 1049, '1900-01-01', '0.00', 'Ipad 4 - 0201', 0),
(170, 'HP27J-2C496-83KXB-RGMX6-8QJQG', 1020, '1900-01-01', '0.00', 'MS Office for Jonny D', 1),
(171, '7N4QY-DFGWD-P6662-CFCHG-QYFP2', 1021, '1900-01-01', '0.00', 'MS Office for WS0215 (Simeon Laptop)', 1),
(172, '0140', 1022, '1900-01-01', '0.00', 'Viewsonic VA2248-LED - 0140', 1),
(198, '0109', 1037, '1900-01-01', '0.00', 'WS0109', 1),
(199, '0324', 1052, '1900-01-01', '0.00', 'Philips 23.6" Monitor 0324', 1)
;
CREATE TABLE [Asset-User]
([ID] int, [Asset_ID] int, [User_ID] int, [Sign_Out_Date] datetime, [Return_Date] datetime, [Perm_Signout] int)
;
INSERT INTO [Asset-User]
([ID], [Asset_ID], [User_ID], [Sign_Out_Date], [Return_Date], [Perm_Signout])
VALUES
(2, 1, 1, '2014-03-29 00:00:00', '2014-03-29 00:00:00', 0),
(3, 1, 1, '2014-03-29 00:00:00', '2014-03-29 00:00:00', 0),
(4, 1, 1, '2014-03-29 00:00:00', '2014-03-29 00:00:00', 0),
(5, 1, 1, '2014-03-29 00:00:00', '2014-03-29 00:00:00', 0),
(6, 1, 1, '2014-03-29 00:00:00', '2014-03-29 00:00:00', 0),
(7, 1, 1, '2014-03-29 00:00:00', '2014-03-29 00:00:00', 0),
(8, 1, 1, '2014-03-29 00:00:00', '2014-03-29 00:00:00', 0),
(9, 1, 1, '2014-03-29 00:00:00', '2014-03-29 00:00:00', 0),
(10, 1, 1, '2014-03-29 00:00:00', '2014-03-29 00:00:00', 0),
(11, 1, 1, '2014-03-29 00:00:00', '2014-03-29 00:00:00', 0),
(1002, 1, 1, '2014-04-01 00:00:00', '2014-04-01 00:00:00', 0),
(1003, 1, 1, '2014-01-01 00:00:00', '2014-01-01 00:00:00', 1)
;
CREATE TABLE Company_Users
([ID] int, [Name] varchar(14), [Domain_Username] varchar(14), [Dept] varchar(16), [Email] varchar(25), [DD_Ext] int, [Job_Title] varchar(30), [Deleted_Left] int)
;
INSERT INTO Company_Users
([ID], [Name], [Domain_Username], [Dept], [Email], [DD_Ext], [Job_Title], [Deleted_Left])
VALUES
(1, 'Neil Smithson', 'Neil.Smithson', '2nd Line Support', 'neil.smithson#dezrez.com', 3041, 'Second Line Support Technician', 0)
;
CREATE TABLE Global_Types
([ID] int, [Name] varchar(13), [Description] varchar(54))
;
INSERT INTO Global_Types
([ID], [Name], [Description])
VALUES
(1, 'PC', 'Desktop PC')
;
This is not really an answer but will show you how you could rework this query using aliases and the (not really) newer join style.
SELECT au.ID
, au.Asset_ID
, a.ID
, a.Signed_Out
, a.Asset_Tag_Serial_Num
, a.Name_Hostname
, a.Type_ID
, at.ID
, at.Name_Model
, au.User_ID
, cu.ID
, au.Sign_Out_Date
, au.Return_Date
, au.[Perm_Signout?]
FROM [Asset-User] au
join Assets a on au.Asset_ID = a.ID
join Asset_Type at on a.Type_ID = at.ID
join Company_Users cu on au.User_ID = cu.ID
WHERE au.User_ID = '1'
AND a.Signed_Out = '1'

WITH keyword is required

While running the following SQL query -
INSERT INTO Countries ('sno', 'Name' ) VALUES
(1, 'Afghanistan'),
(2, 'Albania'),
(3, 'Algeria'),
(4, 'American Samoa'),
(5, 'Andorra'),
(6, 'Angola'),
(7, 'Anguilla'),
(8, 'Antarctica'),
(9, 'Antigua and Barbuda'),
(10, 'Argentina'),
(11, 'Armenia'),
(12, 'Armenia'),
(13, 'Aruba'),
(14, 'Australia'),
(15, 'Austria'),
(16, 'Azerbaijan'),
(17, 'Azerbaijan'),
(18, 'Bahamas'),
(19, 'Bahrain'),
(20, 'Bangladesh'),
(21, 'Barbados'),
(22, 'Belarus'),
(23, 'Belgium'),
(24, 'Belize'),
(25, 'Benin'),
(26, 'Bermuda'),
(27, 'Bhutan'),
(28, 'Bolivia'),
(29, 'Bosnia and Herzegovina'),
(30, 'Botswana'),
(31, 'Bouvet Island'),
(32, 'Brazil'),
(33, 'British Indian Ocean Territory'),
(34, 'Brunei Darussalam'),
(35, 'Bulgaria'),
(36, 'Burkina Faso'),
(37, 'Burundi'),
(38, 'Cambodia'),
(39, 'Cameroon'),
(40, 'Canada'),
(41, 'Cape Verde'),
(42, 'Cayman Islands'),
(43, 'Central African Republic'),
(44, 'Chad'),
(45, 'Chile'),
(46, 'China'),
(47, 'Christmas Island'),
(48, 'Cocos (Keeling) Islands'),
(49, 'Colombia'),
(50, 'Comoros'),
(51, 'Congo'),
(52, 'Congo, The Democratic Republic of The'),
(53, 'Cook Islands'),
(54, 'Costa Rica'),
(55, 'Cote Divoire'),
(56, 'Croatia'),
(57, 'Cuba'),
(58, 'Cyprus'),
(59, 'Cyprus'),
(60, 'Czech Republic'),
(61, 'Denmark'),
(62, 'Djibouti'),
(63, 'Dominica'),
(64, 'Dominican Republic'),
(65, 'Easter Island'),
(66, 'Ecuador'),
(67, 'Egypt'),
(68, 'El Salvador'),
(69, 'Equatorial Guinea'),
(70, 'Eritrea'),
(71, 'Estonia'),
(72, 'Ethiopia'),
(73, 'Falkland Islands (Malvinas)'),
(74, 'Faroe Islands'),
(75, 'Fiji'),
(76, 'Finland'),
(77, 'France'),
(78, 'French Guiana'),
(79, 'French Polynesia'),
(80, 'French Southern Territories'),
(81, 'Gabon'),
(82, 'Gambia'),
(83, 'Georgia'),
(84, 'Georgia'),
(85, 'Germany'),
(86, 'Ghana'),
(87, 'Gibraltar'),
(88, 'Greece'),
(89, 'Greenland'),
(90, 'Greenland'),
(91, 'Grenada'),
(92, 'Guadeloupe'),
(93, 'Guam'),
(94, 'Guatemala'),
(95, 'Guinea'),
(96, 'Guinea-bissau'),
(97, 'Guyana'),
(98, 'Haiti'),
(99, 'Heard Island and Mcdonald Islands'),
(100, 'Honduras'),
(101, 'Hong Kong'),
(102, 'Hungary'),
(103, 'Iceland'),
(104, 'India'),
(105, 'Indonesia'),
(106, 'Indonesia'),
(107, 'Iran'),
(108, 'Iraq'),
(109, 'Ireland'),
(110, 'Israel'),
(111, 'Italy'),
(112, 'Jamaica'),
(113, 'Japan'),
(114, 'Jordan'),
(115, 'Kazakhstan'),
(116, 'Kazakhstan'),
(117, 'Kenya'),
(118, 'Kiribati'),
(119, 'Korea, North'),
(120, 'Korea, South'),
(121, 'Kosovo'),
(122, 'Kuwait'),
(123, 'Kyrgyzstan'),
(124, 'Laos'),
(125, 'Latvia'),
(126, 'Lebanon'),
(127, 'Lesotho'),
(128, 'Liberia'),
(129, 'Libyan Arab Jamahiriya'),
(130, 'Liechtenstein'),
(131, 'Lithuania'),
(132, 'Luxembourg'),
(133, 'Macau'),
(134, 'Macedonia'),
(135, 'Madagascar'),
(136, 'Malawi'),
(137, 'Malaysia'),
(138, 'Maldives'),
(139, 'Mali'),
(140, 'Malta'),
(141, 'Marshall Islands'),
(142, 'Martinique'),
(143, 'Mauritania'),
(144, 'Mauritius'),
(145, 'Mayotte'),
(146, 'Mexico'),
(147, 'Micronesia, Federated States of'),
(148, 'Moldova, Republic of'),
(149, 'Monaco'),
(150, 'Mongolia'),
(151, 'Montenegro'),
(152, 'Montserrat'),
(153, 'Morocco'),
(154, 'Mozambique'),
(155, 'Myanmar'),
(156, 'Namibia'),
(157, 'Nauru'),
(158, 'Nepal'),
(159, 'Netherlands'),
(160, 'Netherlands Antilles'),
(161, 'New Caledonia'),
(162, 'New Zealand'),
(163, 'Nicaragua'),
(164, 'Niger'),
(165, 'Nigeria'),
(166, 'Niue'),
(167, 'Norfolk Island'),
(168, 'Northern Mariana Islands'),
(169, 'Norway'),
(170, 'Oman'),
(171, 'Pakistan'),
(172, 'Palau'),
(173, 'Palestinian Territory'),
(174, 'Panama'),
(175, 'Papua New Guinea'),
(176, 'Paraguay'),
(177, 'Peru'),
(178, 'Philippines'),
(179, 'Pitcairn'),
(180, 'Poland'),
(181, 'Portugal'),
(182, 'Puerto Rico'),
(183, 'Qatar'),
(184, 'Reunion'),
(185, 'Romania'),
(186, 'Russia'),
(187, 'Russia'),
(188, 'Rwanda'),
(189, 'Saint Helena'),
(190, 'Saint Kitts and Nevis'),
(191, 'Saint Lucia'),
(192, 'Saint Pierre and Miquelon'),
(193, 'Saint Vincent and The Grenadines'),
(194, 'Samoa'),
(195, 'San Marino'),
(196, 'Sao Tome and Principe'),
(197, 'Saudi Arabia'),
(198, 'Senegal'),
(199, 'Serbia and Montenegro'),
(200, 'Seychelles'),
(201, 'Sierra Leone'),
(202, 'Singapore'),
(203, 'Slovakia'),
(204, 'Slovenia'),
(205, 'Solomon Islands'),
(206, 'Somalia'),
(207, 'South Africa'),
(208, 'South Georgia and The South Sandwich Islands'),
(209, 'Spain'),
(210, 'Sri Lanka'),
(211, 'Sudan'),
(212, 'Suriname'),
(213, 'Svalbard and Jan Mayen'),
(214, 'Swaziland'),
(215, 'Sweden'),
(216, 'Switzerland'),
(217, 'Syria'),
(218, 'Taiwan'),
(219, 'Tajikistan'),
(220, 'Tanzania, United Republic of'),
(221, 'Thailand'),
(222, 'Timor-leste'),
(223, 'Togo'),
(224, 'Tokelau'),
(225, 'Tonga'),
(226, 'Trinidad and Tobago'),
(227, 'Tunisia'),
(228, 'Turkey'),
(229, 'Turkey'),
(230, 'Turkmenistan'),
(231, 'Turks and Caicos Islands'),
(232, 'Tuvalu'),
(233, 'Uganda'),
(234, 'Ukraine'),
(235, 'United Arab Emirates'),
(236, 'United Kingdom'),
(237, 'United States'),
(238, 'United States Minor Outlying Islands'),
(239, 'Uruguay'),
(240, 'Uzbekistan'),
(241, 'Vanuatu'),
(242, 'Vatican City'),
(243, 'Venezuela'),
(244, 'Vietnam'),
(245, 'Virgin Islands, British'),
(246, 'Virgin Islands, U.S.'),
(247, 'Wallis and Futuna'),
(248, 'Western Sahara'),
(249, 'Yemen'),
(250, 'Yemen'),
(251, 'Zambia'),
(252, 'Zimbabwe');
following error code is seen on microsoft sql server-
Msg 215, Level 16, State 1, Line 1
Parameters supplied for object 'Countries' which is not a function. If the parameters are intended as a table hint, a WITH keyword is required.
Please help by sharing the reason ?
Don't use single quotes for column name.
INSERT INTO Countries ([sno], [Name])...
You can use brackets normally.
Or you can use double quote " if SET QUOTED_IDENTIFIER is ON (it should be by default)
Currently you have string literals which is causing SQL Server to interpret the code way different to what you expect
You could leave all the bracketed section out all together: SQL Fiddle
INSERT INTO Countries VALUES
This is therefore none explicit and not best practice (see comment by #AaronBertrand) - but still an alternative.