sql

What is wrong with this JOIN query?

I have a list of tenant reports, each link pointing to a report ID. I need this query to select the report information, and some of the information related to the tenant who submit it. This query gets the report information correctly, but returns copies of it with every tenant attached to it: SELECT reports.person_reporting, reports....

how to do a SQL insert with a value with an apostrophe in it

what is the correct SQL syntax to insert a value with an apostrophe in it. Insert into Person (First, Last) Values 'Joe', 'O'Brien' i keep getting an error as i thinks the apostrophe after the O is the ending tag for the value ...

Sending/Recieving/Interepreting Dynamic Email

Hey guys here's a good question.. I wanted to write a program that can receives an email, interprets what the message is, then performs a calculation, then responds based on the email received. For example... The mail server receives an email that has "option 1" in the body...then somehow the mail server asks the program what it should...

Best practices on cache implementation

I would need to implement cache, which would need to perform SQL queries and cache results. So, I would love to read something about best practices of doing that; how do properly, staling cache results, checking, etc. Particularly, I would probably benefit from learning how Hibernate is doing that? Or some other good players :-) ...

Limit calls to external database with Python CGI

I've got a Python CGI script that pulls data from a GPS service; I'd like this information to be updated on the webpage about once every 10s (the max allowed by the GPS service's TOS). But there could be, say, 100 users viewing the webpage at once, all calling the script. I think the users' scripts need to grab data from a buffer page ...

SQL issue,challenge

Say we have two entities:teacher and student. each teacher has multiple student. Now I want to: query for at most 5 teachers,and for each teacher, no more than 10 of his student. So far this can be done quite easily by: select *, ( select GROUP_CONCAT('<sid>',students.name,'</sid>') from students on teachers.id=students.teacher lim...

How to use OpenBase SQL in Objective-c for iphone?

Hi, I trying to use OpenBase SQL in my code to save large amount of data. But I have one difficulty regarding this, I am not able to find the frameworks required for using OpenBase SQL in my code. I have found some coding part from the net but that is not working since no framework for OpenBase is added. Can anyone help me with this......

Will SQL 2008 query opmtimizer optimize this query?

Have I to break this query SELECT ISNULL(SUM(AF.[amount]), 0) AS [firm], ISNULL(SUM(ACA.[amount]), 0) AS [cash], ISNULL(SUM(AC.[amount]), 0) AS [client], ISNULL(SUM(AFR.[amount]), 0) AS [fr], ISNULL((SUM(AF.[amount]) + SUM(ACA.[amount]) - (SUM(AC.[amount]) + SUM(AFR.[amount])), 0) AS [total] FROM ... into two: DECLARE ...

Accessing an Access DB from Outlook via VBA

Hi The situation: In Outlook I get a message from a server. The content of the message needs to be put into an Access db. But, there may not exist another message with the same date. So, I need to look into a db if there is already a message with the same date and time. If there exists one, then it needs to be replaced and otherwise th...

generic stored procedures in oracle

i want to write a generic stored procedure in oracle .For example i want to take table name as input and then do maipulations on it. I want to learn some sample generic codes and the basica of writing generic stored procedures in oracle. Can any one provie code snippets/ links to websites or other material for this? ...

How to write this challenging SQL (MySQL) command?

This is the scenario: I am developing a website which is similar to stackoverflow.com. After an asker/seeker posts his question, other users can post their answers to the question. A user can post more than one answer to the same question, but usually only the latest answer will be displayed. User can give comments on an answer, if comme...

MySQL UNION print every other

How can I make a sql query like the following: (SELECT `name` FROM table1) UNION (SELECT `name` FROM table2) return each other. Ie. name1 from table1, name1 from table2, name2 from table1, name2 from table2 and so on? Edit: Table1 name Hello world Table2 name guten tag The output wanted: Hello guten world tag and this should...

How we can use CTE in subquery in sql server?

How we can use CTE in subquery in sql server? like .. select id (i want to use CTE here), name from table_name ...

SQL Syntax to Pivot multiple tables

Hi, I have spent the past couple of days working on this and am going around in circles. My question is based around the answer I accepted in this post: stackoverflow question I now have my data moved from a single 400 column table to a much more managable database structure with many thanks to Damir Sudarevic. My database looks li...

Chaning varchar Meridiem Time to Twenty Four Hour time in Sql

I have this type of data TimeOFDay column is varchar. I want to change this time in 24 hour time, using SQL, and updating TwentyFourHourTime column. TwentyFourHourTime column is also varchar. How can I do this. Thanks. ...

C# When creating a table I get "incorrect syntax" error if my column / field name contains a "-" hyphen.

Hi all, Below is a snippet of my code, when a table name contains a hyphen, I get the error below. How can I fix this? Thanks for the help. ex = {"ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '-'."} ...

Join results from tables with same name from different databases

Hi, Lets say we have two databases, one named db1, the other one named db2. Both databases have a table called Employees. Is there anyway to join results from both tables even though they have the same name? Note that the two tables do NOT have conflicting field names. I know this is stupid but we had to make an extension database to t...

SQL repeat events by timer

I want that a column of my database, composed by float random numbers, change every x seconds determined by a timer. I read about Schedule Tasks Events but i can't work it. Please help ...

[SQL] Artist-tag database: Getting tags

I'm creating a database that's going to contain various artists which can be tagged with several tags. It's a standard many-to-may relation and my database looks like this: artist: ID name tag: ID name tagID: tagID artistID Say I've got two tagIDs, X and Y. What I want to do is to find all the tags that have an artist in...

Why do I get an Arithmetic overflow error converting numeric to data type numeric in ADO.NET?

Original Question: Why do I get an Arithmetic overflow error converting numeric to data type numeric in ADO.NET code using the Money Data Type when amount is greater than $999,999,99? Just as the question says... I have a bit of ADO.net code in the data access layer that talks to a Sql Server 2008 database. There is an Amount column...