case

What is wrong with my sqlite3 CASE statement?

回眸只為那壹抹淺笑 提交于 2019-12-02 13:06:27
问题 My code follows: SELECT COUNT(_id) AS count FROM general WHERE _id = 1 CASE WHEN count > 0 THEN UPDATE general SET userGivenId = 'xxx' WHERE _id = 1 ELSE INSERT INTO general (userGivenId) VALUES ('xxx' ) END With the error: android.database.sqlite.SQLiteException: near "CASE": syntax error: , while compiling: SELECT COUNT(_id) AS count FROM general WHERE _id = 1 CASE WHEN count > 0 THEN UPDATE general SET userGivenId = 'xxx' WHERE _id = 1 ELSE INSERT INTO general (userGivenId) VALUES ('xxx' )

Splitting value of a varchar column into two columns

会有一股神秘感。 提交于 2019-12-02 12:15:20
If I have a column in which strings vary in length but they ALL have a slash \ within, how can I SELECT to have one column display everything BEFORE the \ and another column displaying everything AFTER the \ ? name column1 column2 DB5697\DEV DB5697 DEV I have seen CHARINDEX and REVERSE on MSDN but haven't been able to put together a soltuion. How can I best split a varchar/string column value into 2 columns in a result set in TSQL ? How about the following ( SQL Fiddle ): SELECT m.name, LEFT(m.name, CHARINDEX('\', m.name) - 1) AS column1, RIGHT(m.name, LEN(m.name) - CHARINDEX('\', m.name)) AS

MySQL ORDER BY depending on CASE order ASC or DESC

旧巷老猫 提交于 2019-12-02 11:12:33
问题 I want based on a value queried from another table order ASC or DESC. So something like this: SELECT * FROM table ORDER BY CASE (SELECT sorting from table2 WHERE table2.id = ?) WHEN 1 THEN table.date ASC END WHEN 0 THEN table.date DESC END END Is anything like that available in MySQL? I've seen for MS-SQL Server some solution: how to order 2 SQL Fields in asc and desc dynamically EDIT : I just saw I made a mistake in the description, fixed. 回答1: order by if((select sorting from table2 where

select with count for years

折月煮酒 提交于 2019-12-02 10:49:58
问题 I have pickup table which looks like this create table Pickup ( PickupID int IDENTITY, ClientID int , PickupDate date , PickupProxy varchar (200) , PickupHispanic bit default 0, EthnCode varchar(5) , CategCode varchar (2) , AgencyID int, Primary Key (PickupID), ); and it containe pickups for clients I need to create report based on this table which should looks like this I know i need to use CASE but really do not know how to put years and calculate average pickups for each year. and how to

Average and Case in SQL

杀马特。学长 韩版系。学妹 提交于 2019-12-02 10:35:57
I am trying to generate a report and the following code does not produce the desired results which gives me 2 lines rather than one. The ScoreTypeID could have values of 22, 52, 3 or 4 . if it is 22 or 52, I need the average and if not I need to show 0. Any idea what may be the problem ? Thanks. CASE WHEN FAS1.ScoreTypeID = 22 THEN avg(fas1.totalscore) WHEN FAS1.ScoreTypeID = 52 THEN avg(fas1.totalscore) ELSE 0 END AS 'Total Score', I think in your full query, you are missing the GROUP BY clause, eg SELECT ... FROM .... WHERE .. GROUP BY FAS1.ScoreTypeID I think this is what you want: coalesce

Another alternating-case in-a-string in Python 3.+

a 夏天 提交于 2019-12-02 10:17:31
问题 I'm very new to Python and am trying to understand how to manipulate strings. What I want to do is change a string by removing the spaces and alternating the case from upper to lower, IE "This is harder than I thought it would be" to "ThIsIsHaRdErThAnItHoUgHtItWoUlDbE" I've cobbled together a code to remove the spaces (heavily borrowed from here): string1 = input("Ask user for something.") nospace = "" for a in string1: if a == " ": pass else: nospace=nospace+a ... but just can't get my head

Trying to get a value from 5 different tables based on another value

橙三吉。 提交于 2019-12-02 09:51:23
问题 I'm trying to get the date value from 5 different tables based on the usertype value and display it on DATATABLES table . For example :- if usertype value is 2 than I want to get the date value from table table_two . Here is what I have got so far : SELECT CASE WHEN tm.usertype = 1 THEN type_1.date WHEN tm.usertype = 2 THEN type_2.date WHEN tm.usertype = 3 THEN type_3.date WHEN tm.usertype = 4 THEN type_4.date WHEN tm.usertype = 5 THEN type_5.date END, tm.id, tm.usertype FROM table_main tm

Any ideas how to determine what age group an individual belongs in Excel?

点点圈 提交于 2019-12-02 09:46:54
I have 2 columns in an Excel spread sheet. First column header is called AGE and the second column header is called Age_Group. The ages in the AGE column are between 18 and 45. There could be multiple rows with same age. I am tasked with determining what age group a certain age falls into and then print out that age group. For instance, if someone’s age is 18, I would like to use IF statement or CASE statement to determine that age 18 is between 18 and 24 and then put that value into Age_Group column as 18-24. If age is 19, again, it will fall into the group of 18-24 in Age_Group column. If

MS Access Query with CASE statement

风流意气都作罢 提交于 2019-12-02 09:22:11
I just want to get the value of one table "b" if table "a" value is "-" If the value at table "b" is empty then get the value of table "a" even if it's "-" Microsoft Access says "Missing operator" with this query: SELECT ts.data_generacio, ts.estat, ts.exercici, Month(tsl.data) AS Mes, Day(tsl.data) AS Dia, tsl.data, tsl.cod_treb, t.nom_treb, tsl.hores, p.cod_proj, p.acronim AS nom_proj, j.justificacio, tsl.timesheet_id, p.ref, CASE WHEN tsl.activitat != '' THEN tsl.activitat ELSE ts.activitat END AS Activitat FROM timesheet_lines AS tsl LEFT JOIN timesheets AS ts ON tsl.timesheet_id = ts.id

CRM 2011 - Using contact data on Case form

雨燕双飞 提交于 2019-12-02 09:19:40
问题 I've installed CRM 2011 to see if I can tailor it to our business. We do repairs, I want to be able to book in a contact (client) and then a case and have the clients number and address print on the case form. All I can find are fields relevant to the case and not client, any idea on how I can select them? 回答1: To get fields from the contact onto the case form you could - Create redundant fields on the case form for the fields that you want to port over from the contact, and then edit the