Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Mohamed Faisal
Yak Posting Veteran
51 Posts |
Posted - 2013-08-10 : 14:49:54
|
My code is select *from Student where DATEDIFF(YY,[Date],getdate())>=17AND YEAR = 1group by StudentName LIKE 'IT%'order by Name ASC, Age DESC;And having a problem to view the DATEDIFF as age and also having error:Msg 156, Level 15, State 1, Line 5Incorrect syntax near the keyword 'LIKE'.Anyone could could point out what is wrong.Thanks |
|
Mohamed Faisal
Yak Posting Veteran
51 Posts |
Posted - 2013-08-10 : 16:01:50
|
I have correct the SQL but need help in how to use the Order by for a virtual column Age:Select *,DateDiff(YY,[DateOfBirth],getdate())As Agefrom StudentWhere Year = 1 and StudentNumber like 'IT%' and Age >= 17order by Name Asc,Age Desc; |
 |
|
pascal_jimi
Posting Yak Master
167 Posts |
Posted - 2013-08-10 : 16:06:49
|
must case when not group by my friendhttp://sql-az.tr.gg/ |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-08-10 : 16:12:45
|
[code]SELECT *FROM dbo.StudentWHERE [Date] >= DATEADD(YEAR, DATEDIFF(YEAR, '19170101', GETDATE()), '19000101') AND [Year] = 1 AND StudentName LIKE 'IT%'ORDER BY Name, Age DESC;[/code] Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
 |
|
Mohamed Faisal
Yak Posting Veteran
51 Posts |
Posted - 2013-08-10 : 16:29:11
|
How could i use the Order by Age Desc i am getting error |
 |
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-08-10 : 16:39:13
|
quote: Originally posted by Mohamed Faisal How could i use the Order by Age Desc i am getting error
Change SwePeso's code as follows: [CODE]SELECT *FROM dbo.StudentWHERE [Date] >= DATEADD(YEAR, DATEDIFF(YEAR, '19170101', GETDATE()), '19000101') AND [Year] = 1 AND StudentName LIKE 'IT%'ORDER BY Name, [Date] DESC;[/CODE] |
 |
|
|
|
|
|
|