I have the following piece of SQL: select DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)) which comes through as this format: 2012-02-29 23:59:59.000 I need the exact piece of code with the …
Tag: sql
VB.net SQL error Must Declare the Scalar Variable
Hi I have been stuck for a long time on this simple but obtuse message “Must Declare the Scalar Variable” I have a vb.net and SQL code that inserts data into a simple table. It works OK with sample …
SQL select * from column where year = 2010
This is probably a simple where clause but I want to say, from columnX (which is datetime) I want all rows where just the year = 2010. so: Answer Regarding index usage (answering Simon’s comment): if you have an index on Columnx, SQLServer WON’T use it if you use the function “year” (o…
Count records for every month in a year
I have a table with total no of 1000 records in it.It has the following structure: I want to calculate no of records for every month in year-2012 Is there any way that should solve my issue in a single shot? I tried: Answer
Select a column if other column is null
I need to select a field called ProgramID from a table and if the ProgramID is NULL then I need to select the value in the InterimProgramID from the same table and alias it as ProgramID. How can I …
Sqlite3 – Update table using Python code – syntax error near %s
This is my Python code – cursor.execute(“””UPDATE tasks SET task_owner=%s,task_remaining_hours=%s, task_impediments=%s,task_notes=%s WHERE task_id=%s”””, (…
How can I prevent 2nd order SQL attacks?
I’m using PHP PDO for my queries, everywhere, but I read that in very rare cases there could still be “second order injections” where an unsafe variable is stored then executed when used in another statement. Will prepared statements still protect against this? As long as I make sure I alway…
Delete row if table exists SQL
I have a script that drops a load of tables using DROP TABLE IF EXISTS, this works. There is also a delete in this script to DELETE a row from another table that I do not manage. This table may or …
SQLite in Android How to update a specific row
I’ve been trying to update a specific row for a while now, and it seems that there are two ways to do this. From what I’ve read and tried, you can just use the: execSQL(String sql) method or the: update(String table, ContentValues values, String whereClause, String[] whereArgs) method. (Let me kno…
SQL: Join tables on substrings
I have a table A with the string-column a and a table B with the string-column b. a is a substring of b. Now I want to join the the two tables on a and b. Is this possible? I want something like this: Select * from A,B where A.a *”is substring of”* B.b How can I write this in