sql

C++ Access to SQL Server from Linux

I need to write some data to SQL Server database from Linux in C++. I found this sqlapi.com But I think, at first ODBC driver has to be installed and has to work. I folowed this adminlife.net/allgemein/mssql-zugriff-unter-debian-etch-mit-unixodbc-und-freetds/ or this http://b.gil.megiteam.pl/2009/11/linux-odbc-to-mssql/ But it didn't...

How to select a subset of results from a select statement

I have a table that stores RDF triples: triples(triple_id, sub_id, pre_id, obj_id) The method (I need to write) will receive an array of numbers which correspond to pre_id values. I want to select all sub_id values that have a corresponding pre_id for all the pre_ids in the array that is passed in. E.g. if I had a single pre_id values...

How can I synchronize one set of data with another?

I have an old database and a new database. The old records were converted to the new database recently. All our old applications continue to point to the old database, but the new applications point to the new database. Currently the old database is the only one being updated, so throughout the day the new database becomes out of sync...

Calculating multiple column average in SQLite3

I need to average some values in a row-wise fashion, rather than a column-wise fashion. (If I were doing a column-wise average, I could just use avg()). My specific application of this requires me ignore NULLs in averaging. It's pretty straightforward logic, but seems awfully difficult to do in SQL. Is there an elegant way of doing m...

query SQL how to check all records from a three table join share the same value

Hello Since i'm a poor sql developer, i need support to write a sql query for the following scenario (just a simplified example of my situation): i've got 3 tables, say employe table,department table and companybranch table. the dept column , on the employe table is a fk on the department table; the branch column on the department table...

Why connection in Python's DB-API does not have "begin" operation?

Working with cursors in mysql-python I used to call "BEGIN;", "COMMIT;", and "ROLLBACK;" explicitly as follows: try: cursor.execute("BEGIN;") # some statements cursor.execute("COMMIT;") except: cursor.execute("ROLLBACK;") then, I found out that the underlying connection object has the corresponding methods: try: c...

SQL:Placing Column values in variables using single query

In SQL server,How can i place the value of more than one column in variables using one query Ex : My query is : SELECT ET.ID,ET.Description,ET.DefaultTemplateText FROM TBL_EMAILTEMPLATE ET WHERE ET.NAME='OneWeekReminder' I want to place the Column values in variables. Thanks in advance for the help ...

Is SQL DATEDIFF(year, ..., ...) an Expensive Computation?

I'm trying to optimize up some horrendously complicated SQL queries because it takes too long to finish. In my queries, I have dynamically created SQL statements with lots of the same functions, so I created a temporary table where each function is only called once instead of many, many times - this cut my execution time by 3/4. So my ...

Correlated SQL Join Query from multiple tables

I have two tables like the ones below. I need to find what exchangeRate was in effect at the dateOfPurchase. I've tried some correlated sub queries, but I'm having difficulty getting the correlated record to be used in the sub queries. I expect a solution will need to follow this basic outline: SELECT only the exchangeRates for the ...

SQL: Need to SUM on results that meet a HAVING statement

I have a table where we record per user values like money_spent, money_spent_on_candy and the date. So the columns in this table (let's call it MoneyTable) would be: UserId Money_Spent Money_Spent_On_Candy Date My goal is to SUM the total amount of money_spent -- but only for those users where they have spent more than 10% of their...

Problem with oracle stored procedure - parameters

I have this stored procedure: CREATE OR REPLACE PROCEDURE "LIQUIDACION_OBTENER" ( p_Cuenta IN NUMBER, p_Fecha IN DATE, p_Detalle OUT LIQUIDACION.FILADETALLE%TYPE ) IS BEGIN SELECT FILADETALLE INTO p_Detalle FROM Liquidacion WHERE (FILACUENTA = p_Cuenta) AND (FILAFECHA = p_Fecha); END; / ...and my c# code: ...

SQL Server 2005 - How to find out what transaction log files have been restored.

How can you find out what transaction log backup files have been restored using SQL in SQL Server 2005? ...

How can I use the "Select" statment from a table with a name that contains blankspaces?

When using this SQL query: "Select * from table_name" what happens if the name of the table contains blankspaces? Is there an special SQL sintax for selecting a table with a name such as "Author Code"? ...

DBCC SHRINKFILE 1 sproc for multiple databases

I have a need to execute DBCC SHRINKFILE for multiple db's within the same sproc. I could create multiple sprocs so it runs within the given context, but I was curious if there were alternatives? ...

Compiled Linq Queries with Built-in SQL functions

I have a query that I am executing in C# that is taking way too much time: string Query = "SELECT COUNT(HISTORYID) FROM HISTORY WHERE YEAR(CREATEDATE) = YEAR(GETDATE()) "; Query += "AND MONTH(CREATEDATE) = MONTH(GETDATE()) AND DAY(CREATEDATE) = DAY(GETDATE()) AND USERID = '" + EmployeeID + "' "; Query += "AND TYPE = '5'"; I then use S...

Impact of ordering of correlated subqueries within a projection

I'm noticing something a bit unexpected with how SQL Server (SQL Server 2008 in this case) treats correlated subqueries within a select statement. My assumption was that a query plan should not be affected by the mere order in which subqueries (or columns, for that matter) are written within the projection clause of the select statement...

SQL IN Statement using like syntax?

I would like to do something like this i.e., use wild card characters in the in clause: SELECT * FROM mytable WHERE keywords IN ('%test%', '%testing%') This is not supported in SQL Server.... Is there some other way to achieve it... Looking for something other than: SELECT * FROM mytable WHERE keywords like '%test%' or keywords like...

Why does GetSqlDecimal throw when GetDecimal doesn't?

I have a database table that has a column of type money, allowing nulls. Using a SqlDataReader named reader, I can do decimal d = reader.GetDecimal(1); which works, unless of course we're reading a null. If I try using SqlDecimal instead--and I thought the whole point of the SqlTypes was to deal with nulls--then I get an invalid cast,...

Query design in SQL - ORDER BY SUM() of field in rows which meet a certain condition

OK, so I have two tables I'm working with - project and service, simplified thus: project ------- id PK name str service ------- project_id FK for project time_start int (timestamp) time_stop int (timestamp) One-to-Many relationship. Now, I want to return (preferably with one query) a list of an arbitrary number of projects, sorted ...

one variable for all the sql output

hi everyone myRs=myStmt.executeQuery("select i_col,col_name from tab_col") i=0 while (myRs.next()): list= myRs.getString("I_COL")+','+myRs.getString("COL_NAME") i have a jython code to run a sql statement i want to store all the row of the sql into a single variable. I used to list to store the value but its always storing only t...