[Solved] SQL, SUM + CASE [closed]

[ad_1] Never use commas in the FROM clause. Always use proper, explicit JOIN syntax. Then, you cannot nest aggregation functions, so this should be sufficient: SELECT o.ID_DOSSIER, SUM(CASE WHEN ID_TYPE IN (‘0’, ‘1’) THEN TTL * -1 WHEN ID_TYPE IN (‘2’, ‘3’) THEN TTL END) FROM ope o JOIN actor a ON o.ID_ACTION = a.ID_ACTION … Read more

[Solved] Cummulative SUM based on columns

[ad_1] No need to make thinks more complicated than they need to be… IF OBJECT_ID(‘tempdb..#TestData’, ‘U’) IS NOT NULL DROP TABLE #TestData; CREATE TABLE #TestData ( ID INT NOT NULL, [Year] INT NOT NULL ); INSERT #TestData (ID, Year) VALUES (1, 2010), (1, 2010), (2, 2010), (2, 2011), (3, 2012), (4, 2013), (5, 2014), (5, … Read more

[Solved] How minimize this mysql query [closed]

[ad_1] Ever heard of JOINing tables? SELECT photo.id FROM product_photo INNER JOIN product_photo AS photo ON photo.product_id = product_photo.product_id AND photo.order >= product_photo.order WHERE product_photo.id = ’33’; The FROM and WHERE parts will select your product id = 33 and then you join product_photo with different alias (yes, you can join the same table multiple … Read more

[Solved] Entering value to database after pressing enter from a textbox [closed]

[ad_1] Use for this KeyDown event private void YourTextBox_KeyDown(object sender, KeyEventArgs e) { String connection= “Data Source=YourServer;Initial Catalog=YourDatabase;user=User;password=YourPassword;Integrated Security=True;”; if (e.KeyCode == Keys.Enter) { string insertCmdText = “INSERT INTO table(column1)values(@valueForColumn1)”; SqlCommand sqlCom = new SqlCommand(insertCmdText,connection); sqlCom.Paramaters.AddWithValue(“@valueForColumn1”,YourTextBox.Text); connection.Open(); sqlCom.ExecuteNonQuery(); connection.Close(); } } But consider that saving into Database after KeyPress event is not a right way … Read more

[Solved] I’m looking for a way to trim a string so that only 6 consecutive digits show

[ad_1] You’re close! You need to use PATINDEX instead of CHARINDEX. After that, you can use SUBSTRING to pull the six numbers out. This should work for you: Select SUBSTRING(d.Notes, PATINDEX(‘%[0-9][0-9][0-9][0-9][0-9][0-9]%’, d.Notes), 6) From YourTable d If there are records in your table that do not have six consecutive numbers, you can use either of … Read more

[Solved] How to store the entered data into a remote database?

[ad_1] I’m assuming you want to communicate with the remote server through API.To Send POST and GET request to the server, means to create a connection between the server and Android Application.There are many libraries to make HTTP request for example Retrofit,Volley etc, These powerful libraries make it easy to consume JSON or XML data.You … Read more

[Solved] SQL select column of attributes with latest date [closed]

[ad_1] Since you didn’t specify which RDBMS you are working on and the table schema, then you can do this: SELECT t1.tenantId, t1.ExpiryDate FROM tenants AS t1 INNER JOIN ( SELECT tenantId, MAX(ExpiryDate) AS LatestExpiryDate FROM tablename GROUP BY tenantId ) AS t1 ON t1.tenantId = t2.tenantId, t1.ExpiryDate = t2.LatestExpiryDate; The inner join will give … Read more

[Solved] SQL query to count numbers [closed]

[ad_1] Try this SELECT Video_id,COUNT(Video_id) FROM tbl Group By Video_id FIDDLE DEMO O/P VIDEO_ID COUNT(VIDEO_ID) 1 3 2 2 4 4 Take a look at these document http://dev.mysql.com/doc/refman/5.1/en/counting-rows.html http://dev.mysql.com/doc/refman/5.1/en/group-by-extensions.html 0 [ad_2] solved SQL query to count numbers [closed]