sql

Escape double quotes in SQL 2005/2008

I have an international company that has recently been added, which is named "BLA "BLAHBLAH" Ltd. (The double quotes are part of the name. ) Whenever a user tries to search for this company, by entering "Blah, or something to that affect, the search fails with a syntax error in SQL server. How can I escape this so the search will not f...

What is the best-practice for nesting PreparedStatements?

I have several instances where that a section of legacy sql statements is based on a dependency. for example. if (x !=null) { SQL = "SELECT z WHERE x > y"; } else { SQL = "SELECT z WHERE x <= y"; } SQL2 = SQL + " JOIN a ON b"; I am creating PreparedStatements out of this legacy code. What is the best-practice here. Should I cre...

Converting the name of a day to its integer representation

In SQL server you can use the DATENAME function to get the day of week as a string declare @date datetime set @date = '12/16/08' select datename(dw, @date) which returns "Tuesday" and you can use the DATEPART function to get the day of week as an integer declare @date datetime set @date = '12/16/08' select datepart(dw, @date) Whic...

SQL Native Client ODBC application not disconnecting after SQLDisconnect and not pooling?

Background: I'm working with a program coded in C++ which uses ODBC on SQL Native Client to establish connections to interact with a SQL Server 2000 database. Problem: My connections are abstracted into an object which opens a connection when the object is instantiated and closes the connection when the object is destroyed. I can see t...

Using user input to find information in a Mysql database

I need to design a program using python that will ask the user for a barcode. Then, using this barcode, it will search a mysql to find its corresponding product. I am a bit stuck on how to get started. Does anyone have any tips for me? ...

Adding to the Where clause of an Update in LinQ-to-Entities

Let's say I have a table called Product, with three columns: Id, CustomerId, Name. Id is the primary key. The schema is outside of the control of my group, and we now have a requirement to always provide CustomerId as a parameter for all queries (selects, updates, deletes). It's a long story I'd rather not get into ... it involves trig...

How can I make this Ruby on Rails page more efficient?

I'm building a site where users can track their collection of figures for Dungeons & Dragons (www.ddmdb.com). The models/relationships involved in this funcitonality are the following: User: id login (username) a bunch of other fields Miniature: id name number (# in the set, not count) release_id (foreign key) a bunch of other fi...

SQL Query for Product-Tag relationship

Hi I have a database for an E-commerce storefront. MSSQL 2008. I have a table called Products and a table called Tags. This is a many to many relationship that is bound together by a table called ProductTags. Products: id, name, price Tags: id, name, sortorder, parentid(allow nulls) ProductTags: productid, tagid I'm trying to creat...

Fast, Free Desktop SQL tool for CSV files

I have a bunch of pretty large CSV (comma separated values) files and I want to analyze them. SQL queries are ideal for this. So far I have been using MS Access to import the CSV files and execute queries on them. However, in addition to having a very bad SQL editor and having stupid arbitrary rules about when a query/table can be opened...

Is it possible to prevent batch update at the sql database level?

A simple stupid "UPDATE table SET something=another WHERE (always true)" in accident will easily destroy everything in the database. It could be a human mistake, an SQL injection/overflow/truncation attack, or a bug in the code who build the WHERE causes. Are popular databases provide a feature that protect tables by limit maximum numbe...

Should a Composite Primary Key be clustered in SQL Server?

Consider this example table (assuming SQL Server 2005): create table product_bill_of_materials ( parent_product_id int not null, child_product_id int not null, quantity int not null ) I'm considering a composite primary key containing the two product_id columns (I'll definitely want a unique constraint) as opposed to a sep...

Compare Strings in Oracle

I need to query a table for values given a string. The table is case sensitive but I want to do a ToLower() in the comparison. Suppose I have a classes table with the following data. class teacher ----------------- Mat101 Smith MAT101 Jones mat101 Abram ENG102 Smith My query should be something like Select teacher From c...

SQL GROUP BY/COUNT even if no results

I am attempting to get the information from one table (games) and count the entries in another table (tickets) that correspond to each entry in the first. I want each entry in the first table to be returned even if there aren't any entries in the second. My query is as follows: SELECT g.*, count(*) FROM games g, tickets t WHERE (t.g...

SQL Statements in a Windows Batch File

Is there any way to have a Windows batch file directly input SQL statements without calling a script? I want the batch file to login to SQL and then enter in the statements directly. EDIT: I'm using Oracle v10g ...

Display a single record (row) as a single column

I'm looking for ways to display a single row of data as a single column (with multiple rows). For example, FieldA FieldB ------- --------- 1 Some Text [row] Header Value [col] ------ ------ FieldA 1 [row1] FieldB SomeText [row2] Is there a way to do this with SQL Server 2005? ...

Aggregate functions in WHERE clause in SQLite

Simply put, I have a table with, among other things, a column for timestamps. I want to get the row with the most recent (i.e. greatest value) timestamp. Currently I'm doing this: SELECT * FROM table ORDER BY timestamp DESC LIMIT 1 But I'd much rather do something like this: SELECT * FROM table WHERE timestamp=max(timestamp) Howeve...

how do we call a c function from an sql script

Hi, how do we call a C function from an SQL script? int get_next_fbill_b2kId_seq_num(b2kIdType seq_val,bankIdPtrType bank_id) { validate_dc_alias(dcAlias); tbaDateType sysDate; tbaGetSystemDateTime(sysDate,NULL,NULL); /* returns in TBA date format */ sysDate[10] = EOS; get_seq_value(next_num_char, 0, FBILL_B2KID_SR...

Exporting Excel cell data to database via Excel macro?

Can I create a macro written in C# for Excel that allows me to export a cell's data to a SQL Server or Access database? Basically, I'd like to create a button in Excel that saves the data in certain cells to a database. Can this be done? Instead of creating a UI from scratch for a program, I've decided using Excel as the user environm...

How to debug parameterized SQL query

I use C# to make connection to a db and then a Ad hoc SQL to get data. This simple SQL query is very convenient to debug since I can log the SQL query string. If I use parametrized SQL query command, is there any way to log sql query string for debug purpose? ...

How do I trim date in PLSQL?

I have a date variable as 24-dec-08 I want only the 08 component from it. How do I do it in a select statement? e.g.: select db||sysdate (this is the component where I want only 08 from the date) from gct; How do i do it? ...