case

Phone number lookups using incoming numbers of varying lengths, with or without prefixes

心已入冬 提交于 2019-12-11 03:17:13
问题 Systems: -Call Center phone system: incoming calls accompanied by the source number, aka Caller ID, aka "ANI" -SQL Server 2005 - the "data warehouse" which stores customer phone numbers ([cANI]), cust names, location, etc. in a table [CustDataByANI] -Stored Procedure - call center software passes the Caller ID (aka ANI) to a SP as a parameter which uses it to perform a presently simple SELECT statement on the CustDataByANI table....WHERE [cANI] = @ANI. This works wonderfully, provided the

SQL Server: difference in days for two dates in separate rows

不想你离开。 提交于 2019-12-11 02:37:35
问题 I am using SQL Server 2012 and working an a report currently that is asking me to find the difference in days between two dates. Basically, for a particular ReportID , I'm trying to find the difference in days between the ( ReportCompletedDate when the ReportType = 'PaperReceived' ) - ( ReportCompletedDate when the ReportType = 'Form Completed' ) I tried to give some records below... ReportID ReportType ReportCompletedDate ------------------------------------------------- 450 PaperReceived 9

Counting the rows of a column where the value of a different column is 1

二次信任 提交于 2019-12-11 02:29:41
问题 I am using a select count distinct to count the number of records in a column. However, I only want to count the records where the value of a different column is 1. So my table looks a bit like this: Name------Type abc---------1 def----------2 ghi----------2 jkl-----------1 mno--------1 and I want the query only to count abc, jkl and mno and thus return '3'. I wasn't able to do this with the CASE function, because this only seems to work with conditions in the same column. EDIT: Sorry, I

SQL IF ELSE / CASE clause in WHERE condition

邮差的信 提交于 2019-12-11 02:14:56
问题 I have a very large MySQL statement looped through php foreach and each loop connected to the previous with union all. I will simplify the statement to the core of my problem, if needed I can of course also add more details later on request. I have this table +--------+-----------+-----------+ | ID | LANG | TITLE | +--------+-----------+-----------+ | 1 | EN | T-A | +--------+-----------+-----------+ | 1 | FR | T-A | +--------+-----------+-----------+ | 2 | FR | T-B | +--------+-----------+--

Group by similar string

烂漫一生 提交于 2019-12-11 01:58:19
问题 Suppose I have a table like this | id_grupo | nombre | |:---------|----------------:| | 1 | Emprendedores 1 | | 2 | Emprendedores 2 | | 3 | Emprendedoras 1 | | 4 | Emprendedoras 2 | | 5 | Los amigos 1 | | 6 | Los amigos 2 | | 7 | Los amigos no 1 | I want to group by name that are equal but ends in different number. If you look closely there are names which consists of two or more words however the difference is the ending. Also there are name which look similar but they are not the same like

Problem with OnKeyDown in Delphi

谁说胖子不能爱 提交于 2019-12-11 01:47:39
问题 I am working with Delphi. I want to track on which key is pressed. I am using KeyDown event of TForm. It is working fine but the problem is that, if I press and lower case letter, though it gives me upper case of that letter. How can I recognize the key pressed is lower case or upper case? 回答1: If you want to track alphanumerical keys, then you should use KeyPress . Try this: procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char); begin ShowMessage(Key); end; The problem with KeyDown

mysql what is the right syntax for this conditional update statement

你。 提交于 2019-12-11 01:15:03
问题 MYSQL, what I want is like update tablename case fieldA when value1 then set fieldX0=xxx,fieldX1=bbb,fieldX2=ccc ... when value2 then set fieldY0=yyy,fieldY1=eee,fieldY2=fff ... end what is the right and simple syntax for it? thank you very much. 回答1: It should be written this way: UPDATE tablename SET fieldX = CASE WHEN fieldA = 'value1' THEN 'xxx' ELSE fieldX END, fieldY = CASE WHEN fieldA = 'value2' THEN 'yyy' ELSE fieldY END WHERE fieldA IN ('value1', 'value2'); Note that: I wrote the

Optimizing CASE WHEN statement in SQL Server WHERE clause condition

旧时模样 提交于 2019-12-10 21:52:31
问题 I am rewriting my sql to reduce the cost of execution and wondering if there is an efficient way to write the below CASE WHEN statements used in WHERE condition: SELECT l.*,tg.* FROM RefTable tg, InputTbl l WHERE tg.areascheme = l.areascheme AND tg.countrycode = l.strareabriefnamel1 AND ( CASE WHEN l.strareabriefnamel2 IS NULL THEN '' ELSE tg.areacode END ) = COALESCE( l.strareabriefnamel2,'' ) AND ( CASE WHEN l.strareabriefnamel3 IS NULL THEN '' ELSE tg.subareaname END ) = COALESCE( l

SQL Server 2012 - Case statement in where clause

我的未来我决定 提交于 2019-12-10 21:32:54
问题 SQL is not my strong suit, but I cannot figure out why this isn't working. I simply want to run a different AND statement based on a value. Specifically, I want to change the datePart in the dateDiff function if foo is = 0 SELECT foo, bar, test FROM table WHERE bar = 1, CASE WHEN foo = 0 AND dateDiff(dd, getDate(), 2 ) < test ELSE AND dateDiff(hh, getDate(), 2 ) < test END 回答1: Try this one - SELECT foo, bar, test FROM [table] WHERE bar = 1 AND ( ( foo = 0 AND DATEDIFF(dd, GETDATE(), 2 ) <

SQL case statement in a stored procedure

浪子不回头ぞ 提交于 2019-12-10 21:26:41
问题 I have a SQL Server stored proc that contains a CASE statement. However, I need to append the values if multiple conditions are true. So if a particular record has an Invalid Date And Mileage exceeded , I would like both values to be displayed in the NotArchiveableReason column. How would I accomplish that? , CASE WHEN DateOfLoss < PolicyStartDate THEN 'Invalid Date' WHEN MilesDriven > TotalMilesAllowed THEN 'Mileage exceeded' WHEN LossStatusCode != 'R' THEN 'Status code is Review' Else