sql

How to test SQL for validity from the command line?

Is there a good tool for ensuring that an SQL query is valid ANSI SQL, and optionally what DBMSs will fail to interpret it? I've found http://developer.mimer.com/validator but I was wondering whether there is a command line tool, preferably open source. ...

Webservice From SQL

Can I call a remote webservice from a Stored Procedure and use the values that areretuned? ...

BindingSource Filter by date

Hello. I want to filter values from database based on date. Date in a database contains values like this: 2008-12-28 18:00:00. And my class has a DateTime variable depending on which I want to filter. Ideally it would work like this: myBindingSource.Filter = "DATE(myDateField) = myDateTime.Date" + adjusting myDateTime.Date format as ne...

Return Object From Webservice

How can I retuen a Object from a web service: [WebMethod] public DataSet GetVendors(string Database) { SqlConnection sqlConn = new SqlConnection(); sqlConn.ConnectionString = GetConnString(Database); // build query string strSQL = @" SELECT [No_] AS [VendorNo], ...

How do I calculate percentages with decimals in SQL?

How can i convert this to a decimal in SQL? Below is the equation and i get the answer as 78 (integer) but the real answer is 78.6 (with a decimal) so i need to show this as otherwise the report wopnt tally up to 100% (100 * [TotalVisit1]/[TotalVisits]) AS Visit1percent ...

grouping records in one temp table

I have a table where one column has duplicate records but other columns are distinct. so something like this Code SubCode version status 1234 D1 1 A 1234 D1 0 P 1234 DA 1 A 1234 DB 1 P 5678 BB 1 A 5678 BB 0 ...

When is the proper time to use the SQL statement "SELECT [results] FROM [tables] WHERE [conditions] FETCH FIRST [n] ROWS ONLY"

I'm not quite sure when selecting only a certain number of rows would be better than simply making a more specific select statement. I have a feeling I'm missing something pretty straight forward but I can't figure it out. I have less than 6 months experience with any SQL and it's been cursory at that so I'm sorry if this is a really s...

How to do equivalent of "limit distinct"?

How can I limit a result set to n distinct values of a given column(s), where the actual number of rows may be higher? Input table: client_id, employer_id, other_value 1, 2, abc 1, 3, defg 2, 3, dkfjh 3, 1, ldkfjkj 4, 4, dlkfjk 4, 5, 342 4, 6, dkj 5, 1, dlkfj 6, 1, 34kjf 7, 7, 34kjf 8, 6, lkjkj 8, 7, 23kj desired output, where limit ...

Using an 'IN' operator with a SQL Command Object and C# 2.0

I would like to call a sql statement such as: Select * From Table Where Column in ('value1', 'value2', 'value3') Is it as simple as setting a command parameter's value equal to "('value1', 'value2', 'value3')"? ...

When using the latest jdbc driver for SQL Server 2005/2008 how do prepared statements, views, and stored procedures compare regarding performance?

When using the latest Microsoft jdbc driver for SQL Server 2005/2008 how do prepared statements, views, and stored procedures compare regarding performance? If I have a plain old select statement with some dynamic where clauses will I see benefits from moving from straight SQL in a prepared statement to a view or even stored procedure?...

Best way to create a SQL Server rollback script?

I am working on some schema changes to an existing database. I backed up the database to get a dev copy, and have made my changes. I will be creating a single roll script to migrate the changes on the production machine in a single transaction. Is there a best practice for creating a rollback script encase a deployment issue arises? B...

SQL Formatter for SQL Management Studio

I was wondering if there is a plugin/tool for SQL Server Management Studio that will format your SQL? I'm working with some large-ish stored procs that are a mangled mess of poorly formatted SQL and it'd be nice if I could just go "Select All -> Format SQL" ...

Worst SQL Ever

What is the worst SQL query you've ever seen? What made it bad? ...

Is this join hint dangerous?

A coworker asked me to look at indexing on some tables because his query was running very long. Over an hour. select count(1) from databaseA.dbo.table1 inner join databaseA.dbo.table2 on (table1.key = table2.key) inner join databaseB.dbo.table3 on (table1.key = table3.key) Note the different databases. This was being run from Databa...

SQL Insert with large dataset

When running a query like "insert into table " how do we handle the commit size? I.e. are all records from anotherTable inserted in a single transaction OR is there a way to set a commit size? Thanks very much, ~Sri PS: I am a first timer here, and this site looks very good! ...

asynchronous select db2

Does db2 support asynchronous SQL operations? I.e. if I execute a select stmt on a table which has 20M rows and I expect back 5M rows. When I run this query via JDBC, I want the control to be returned immediately while the db is executing the query and populating the ResultSet asynchronously in the backend thread. I know some dbs like S...

Find missing values

I have a table, with 2 important columns DocEntry, WebId Sample data is like DocEntry WebId 1 S001 2 S002 3 S003 4 S005 Now as we can notice here, in column WebId, S004 is missing. How can we locate such missing numbers, with a query. Further explanation: The web id should be in increasing order lik...

Getting a query intersection in JPA?

I have: "image" 1:Many "imageToTag" Many:1 "tag" I want to issue a query that will return all images that have at least tags [a, b, c]. It's not clear to me how one can model this in JPQL. I could build the query string dynamically but that's bad for performance and security reasons. Any ideas? ...

Convert XSD into SQL relational tables

Is there something available that could help me convert a XSD into SQL relational tables? The XSD is rather big (in my world anyway) and I could save time and boring typing if something pushed me ahead rather than starting from scratch. The XSD is here if you want to have a look. It's a standardized/localized format to exchange MSDS. ...

Making a SQL Query in two tables

I'm wondering, is it possible to make an sql query that does the same function as 'select products where barcode in table1 = barcode in table2'. I am writing this function in a python program. Once that function is called will the table be joined permanently or just while that function is running? thanks. lincoln. ...