sql

How to Inspect ODBC communication, to see the SQL being passed through?

Is there a tool for windows that we can use to inspect any SQL commands that go through a particular ODBC data source? ...

Determine existence of results in jet SQL?

In Jet, I want to test if certain conditions return any results. I want a query which returns exactly one record: "true" if there are any results, "false" otherwise. This works in MS SQL: SELECT CASE WHEN EXISTS(SELECT * FROM foo WHERE <some condition>) THEN 1 ELSE 0 END; This is what I have tried in Jet: SELECT IIF...

Conditional limit in mySQL query possible???

Hi everyone, i am faced with a decicion regarding handling threaded comments in our project... I have a simple MySQL table which holds all the comments. There are two types: parents and childs. Childs represent a reply to a parent or another child. My problem: -Comment (depth 0) -- Reply Child (depth 1) --- Reply to previous child (de...

Running a query in Page Load a bad idea?

I'm running an ASP.NET app in which I have added an insert/update query to the [global] Page_Load. So, each time the user hits any page on the site, it updates the database with their activity (session ID, time, page they hit). I haven't implemented it yet, but this was the only suggestion given to me as to how to keep track of how man...

Is there a reliable way to convert unzoned datetime into UNIX time_t?

I need to convert a database column in a (MSSQL) database table into UNIX time_t. The problem is that this column does not have a timezone and some dates are from GMT (+0000) and some from BST (+0100). I am working on UK times. Is there a reliable way to convert unzoned datetime into UNIX time_t? I'm currently using SELECT *,DATEDIFF(s...

SSRS - eliminate stray whitespace between textboxes on a report

I have 4 stacked textboxes in the body of an SSRS report and am getting a stray space / extra line between textboxes 3 & 4. This is for an address block - name / title / email / website. Can't put it in a single textbox with intervening vbcrlf tokens because the email and website are links. I've tried formatting it to remove vertica...

Can anyone please help me with this SQL Query (works in SQLite DB Browser, but not in Rails)

Rails has been spitting this out to me: SQLite3::SQLException: near "SELECT": syntax error: SELECT questions.id, questions.text, questions.question_type_id, questions.meta, questions.max_answer_length, COUNT(form_questions.id) AS expr1, (5) AS expr2, CAST(COUNT(form_questions.id) AS REAL) / CAST((...

MySQL: Alternatives to ORDER BY RAND()

I've read about a few alternatives to MySQL's ORDER BY RAND() function, but most of the alternatives apply only to where on a single random result is needed. Does anyone have any idea how to optimize a query that returns multiple random results, such as this: SELECT u.id, p.photo FROM users u, profiles p WHER...

Does using non-SQL databases obviate the need for guarding against "SQL injection"?

This may seem like an obvious (or not so obvious) question, but let me explain. I'm coding up a Google App Engine site using Google's database technology, BigTable. Any App Engine coders will know that Google has its own limited query language called GQL. As a result, I am tempted not to do any checking for SQL (or GQL) injection in my a...

Calculating percentage within a group.

Hello, given a table that for the following commands: select sex, count(*) from my_table group by sex; select sex, employed, count(*) from my_table group by sex, employed; gives: sex | count -------+------ male | 1960 female | 1801 and: sex | employed | count ---------+----------+------- male | f | 1523 ...

how to fetch result from "for xml path"?

Hi. Now I have a stored procedure (SQL server) which will return a XML from "for xml path" statement. I've try to read the response with ExecuteXmlReader and ExecuteReader, but I got nothing. I've google a while but still can't find how to extract the return value, or, how to retrive the return value. Should I use ExecuteXmlReader? or so...

Hide SQL in Profiler

How can I make my SQL statements not to appear in Profiler ? They contain sensitive information and I don't want them to show in Profiler. Thanks for the replies ! ...

SQL Best Practices

Is it good to check that some fields are blank or not from a table and return true or false from a sp Or is it good to fetch the values and check in the code. ...

SQL Server Enterprise Manager Download? (Or Windows 7 equivalent?)

I maintain a couple of older sites running SQL Server 2000 and 2005. On my old XP box I was using SQL Server Enterprise Manager to access them. I'm now on a Windows 7 box. Is that product still available for download/install and will it run on Windows 7? I can't seem to find a download for that specific component. Or is there an alte...

INSERT INTO a table from another table, but with the correct user ID for each comment a user adds.

I have two tables - a 'users' and a 'comments'. They both have the coloum 'IDUsers'. When a user adds a comment I want their user ID to come from the 'users' table and go into the 'comments' table into the 'IDUsers' coloum from the 'IDUsers' coloum. However, at the same time a comment is being added from the user - so I also am using t...

How do you find out the DayOfTheWeek given a datetime in MySql ?

Given a datetime column in mysql 5, I want to find out the day of the week ? But the function DAYOFWEEK returns 1 for Sunday. I want 1 to denote monday, 2 tuesday etc.. and 7 to denote Sunday. Is there a one-liner (that can be embedded in a larger SQL statement) that implements this function ? f(x) => y such that: f(1) = 7 f(...

Getdate() returning same value at different times! What is happening?

The following SQL run against a table with 1 million records is giving the same value for columns Date1 and Date2, and it took 38 seconds to execute. Is this an expected behavior and why? CREATE FUNCTION Fn_Test(@a decimal)RETURNS TABLE AS RETURN ( SELECT @a Parameter, Getdate() Date1, PartitionTest.* FROM PartitionTest ); SELE...

Is there any way to profile .NET Framework?

We have a complex client-server application that is developed using .NET Framework and uses SQL Server 2005. We use LinqToSql but we manage the life time of all the connections and we pass open connections to any DataContext that gets created. We've also used Microsoft WF in this product. WF makes its own connections to persist workflow...

Is it OK to allow sometimes dynamic SQL without sanitization?

My partner on a PHP project objects my practice of always sanitizing integer values in dynamic SQL. We do use parameterized queries when possible. But for UPDATE and DELETE conditions Zend_Db_Adapter requires a non-parameterized SQL string. That's why I, even without thinking, always write something like: $db->delete('table_foo', 'id = ...

Comparing fields in an ORACLE view

I have an ORACLE table which includes the following fields: FieldA1 NUMBER(10,0) FieldA2 VARCHAR2(40 BYTE) FieldB1 NUMBER(10,0) FieldB2 VARCHAR2(40 BYTE) How do I write an ORACLE view that reads from the table and if the following condition is true: FieldA1 matches FieldB1 OR FieldA2 matches FieldB2 outputs the character 'Y' as one ...