1

Hi so I'm trying to learn sql and am working on a small exercise. I want to return all the ids from a table that have a date after 2014. Heres what I have:

     CREATE TABLE Pick_Up(
     eid INT, 
     pid INT,
     cid int,
     datetime DATETIME, 
     );
INSERT INTO Pick_Up (eid, pid,  datetime) 
VALUES (3, 7,'2015/4/23 16:35:05'),
       (4, 6,'2016/3/20/ 9:05:45');
SELECT P.pid
FROM pick_up P
WHERE year(p.datetime)> '2014';

And I thought it would return both tuples but when I run it i get nothing. IF anyone could help by telling me what I can do to have it return both values that would be amazingly awesome!

prance
  • 137
  • 1
  • 3
  • 12

2 Answers2

0

Only issue is syntax error,there is an extra comma,

SELECT P.pid FROM pick_up P WHERE year(p.datetime)> 2014;

Secondly year is numeric not string.

Naruto
  • 4,221
  • 1
  • 21
  • 32
0
SELECT P.pid
FROM pick_up P
WHERE year(p.datetime)> 2014   [ year(p.datetime) may result in integer ]

or try something like this

SELECT P.pid
FROM pick_up P
WHERE datepart(yy,p.datetime)> 2014 
Raviteja
  • 3,399
  • 23
  • 42
  • 69