Linked Questions

0 votes
3 answers
685 views

CASE statement issue [duplicate]

Can anyone help with this error? SQL: SELECT InvoiceDate, BillingAddress, BillingCity, Total, CASE WHEN Total < 2.00 THEN 'Baseline Purchase' WHEN Total BETWEEN ...
Mark_72's user avatar
1 vote
1 answer
5k views

What is wrong with this statement? 'Unknown column'? [duplicate]

I'm not used to the 'as' keyword and I thought it would be a nice idea to use it. So why do I get an 'unknown column' (eid) error? I use mysql... select t1.index as eid, t1.col1 as col1, t1.col2 as ...
pzogr's user avatar
  • 125
1 vote
1 answer
92 views

group by+where on calculated column [duplicate]

SELECT SUM(a)-SUM(b) AS c1, SUM(a) AS c2, SUM(b) AS c3 FROM tbldoc GROUP BY Cid WHERE c1<>0 If you take ( WHERE c1<>0 ) not error Thank you Answer
user39314's user avatar
0 votes
0 answers
37 views

Using Alias in Calculations [duplicate]

I know that this Problem was addressed before but my SQL knowledge is not that good to figure it out. Maybe you can help me. select ProductionLine, Product, POId, BatchNumber, ...
Pascal Sparla's user avatar
103 votes
8 answers
21k views

Does SQL Server read all of a COALESCE function even if the first argument is not NULL?

I'm using a T-SQL COALESCE function where the first argument will not be null on about 95% of the times it is ran. If the first argument is NULL, the second argument is quite a lengthy process: ...
Curtis's user avatar
  • 1,255
39 votes
5 answers
160k views

Logical operators OR AND in condition and order of conditions in WHERE

Let's examine these two statements: IF (CONDITION 1) OR (CONDITION 2) ... IF (CONDITION 3) AND (CONDITION 4) ... If CONDITION 1 is TRUE, will CONDITION 2 be checked? If CONDITION 3 is FALSE, will ...
garik's user avatar
  • 6,752
7 votes
2 answers
10k views

Alias of COUNT is not being "recognized" by SQL Server

I have restored the Northwind database(https://northwinddatabase.codeplex.com/) from a backup file using SQL Server. Trying to execute the following query results in error "Invalid column name '...
Andrei's user avatar
  • 77
4 votes
2 answers
5k views

Why do I need to use a sub query to filter down a grouped select?

If I do this -- SELECT dv.Name ,MAX(hb.[DateEntered]) as DE FROM [Devices] as dv INNER JOIN [Heartbeats] as hb ON hb.DeviceID = dv.ID WHERE DE < '2013-03-04' GROUP BY dv.Name ...
Nate's user avatar
  • 1,707
4 votes
2 answers
802 views

SQL join on an edited field

I'm trying to join Table1 and Table2 on the Url fields. However all the Urls in Table2 end with a "/" as per the example below: Table1 ╔═════════════════════╗ ║ Url1 ║ ╠═══════...
neptr's user avatar
  • 43
1 vote
1 answer
892 views

Invalid Column Name on CONCAT_WS

Sorry if this seems like rambling I'm not typically a DB person just trying to work through an issue. I have two tables cases and legal_entity the data on the two tables looks like this legal_entity ...
Cistoran's user avatar
  • 113
-1 votes
1 answer
40 views

I report SQL sysntax error [closed]

I'm getting sql error for the below select (select ((Select count(student_hash)from ssa.survey_results where question_master_id in (22)and center_id=101100 and answer_master_id in (95,96))*100/ (...
Dango's user avatar
  • 1