sql

UPDATE query works fine when run from Access, but raises SQL syntax error from within C# app

I have a very simple Update statement that will update mail server settings and network credentials info... Query works fine when I run it in Access but C# keeps giving me the error stating that my SQL Syntax is wrong ... I have a dataaccess layer (dal class) and Update instance method pasted belows ... But the problem must be sth else c...

mysql full text search is empty

I am using ruby on rails with a MySQL backend. I have a table called notes and here is the migration I use to create it: def self.up create_table(:notes, :options => 'ENGINE=MyISAM') do |t| t.string :title t.text :body t.timestamps end execute "alter table notes ADD FULLTEXT(title, body)" end I want to do full te...

How do I write a string search query that uses the non-clustered indexing I have in place on the field?

I'm looking to build a query that will use the non-clustered indexing plan on a street address field that is built with a non-clustered index. The problem I'm having is that if I'm searching for a street address I will most likely be using the 'like' eval function. I'm thinking that using this function will cause a table scan instead o...

Oracle SQL - Parsing a name string and converting it to first initial & last name

Hey.. Does anyone know how to turn this string: "Smith, John R" Into this string: "jsmith" ? I need to lowercase everything with lower() Find where the comma is and track it's integer location value Get the first character after that comma and put it in front of the string Then get the entire last name and stick it after the first init...

Nested records is sql server

select Table1.colID, Table1.colName, (select * from Table2 where Table2.colID = Table1.colID) as NestedRows from Table1 The above query gives you this error: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used..... Can anybody explain why this limitat...

Parametise table name in .Net/SQL?

As the topic suggests I wish to be able to pass Table Names as Parameters using .Net (doesn't matter which language really) and SQL. I Know how to do this for values, i.e command.Parameters.AddWithValue("whatever",whatever). Using @whatever in the query to denote the Parameter. The thing is I am in a situation where I wish to be able to...

T-SQL: Comparing Two Tables - Records that don't exist in second table

If UNION ALL is an "addition" in T-SQL. What is the equivalent of subtraction? For example, if I have a table PEOPLE and a table EMPLOYEES. And I know if I remove EMPLOYEES records from PEOPLE I will be left with my companies "CONTRACTORS". Is there a way of doing this that is similar to UNION ALL? One where I don't have to specify any ...

Template Architecture with CGI

Hi, I have a web page that needs to display a sqlite database. Right now i am creating the entire page dynamically through CGI. However, I would rather have one html file and just populate a table within the file with the database content. What is the best method to do that? I am limited to html, javascript and CGI in C. Any help is gre...

Forcing a UNION on an OR for optimization in SQL Server 2000

How can I get a query which uses an OR in the WHERE clause to split itself into two queries with a UNION during compilation? If I manually rewrite it, the query using the UNION is 100x faster than the single query, because it can effectively use different indices in each query of the union. Is there any way I can make the optimizer use...

How do you do many to many table outer joins?

I have 3 tables, foo, foo2bar, and bar. foo2bar is a many to many map between foo and bar. Here are the contents. select * from foo +------+ | fid | +------+ | 1 | | 2 | | 3 | | 4 | +------+ select * from foo2bar +------+------+ | fid | bid | +------+------+ | 1 | 1 | | 1 | 2 | | 2 | 1 | | 2 | 3...

Best practice for returning IEnumerables from LINQ Methods

OK, This question has probably been answered before, but I'm not sure of how to word the Title. I have a class that has methods which return many composite LINQ queries. Most of these queries form Anonymous Types in order to get the data I need. I found out that I'm not able to return an Anonymous Type from a method, so I've been cre...

SQL Server BCP insert additional columns

Hi My reuirement: Input File: 1,abc,xyx 2,def,mno 3,ghi,suv DB Table Structure: Col1 char col2 char col3 char col4 char col5 char Data in Table after BCP: col1 col2 col3 col4 col5 1 abc xyz ab xy 2 def mno de mn 3 ghi suv gh su Basically the col4 and col5 are calculated values from col2 and col3 v...

How do I join to a "fixed vector" in SQL?

By "fixed vector" I mean a static list of values, like 1 through 24. The current query looks like this (simplified) SELECT Period, Profit FROM Projections But the data is "sparse" — so there's not a row for every period. What query will give me a row for peiods 1-24 every time, with zeros (or NULLs) where there's no data? I would...

SQL Server View Problem

We have a View (call it X) that is the base view called by 2 other views(call them Y and Z). Today we made a change to view X, after that view Y and Z started bringing back data that was incorrect. When we were in Management Studio and ran Select * from Y(which is exactly how the view is called in in code) it would get back data that w...

How to design a database schema to support tagging with categories?

I am trying to so something like Database Design for Tagging, except each of my tags are grouped into categories. For example, let's say I have a database about vehicles. Let's say we actually don't know very much about vehicles, so we can't specify the columns all vehicles will have. Therefore we shall "tag" vehicles with information...

Retrieve return value from DB2 stored procedure

I have a block of code that is repeated within a DB2 stored procedure. I would like to separate this out into a new procedure that I can call with parameters and have it return a value. How do I create a procedure to return a value and how do I call this procedure from inside my original procedure? ...

Insert Dates in the return from a query where there is none.

We are building a query to count the number of events per hour, per day. Most days there are hours that do not have any activity and therefore where the query is run the count of activities per hour show up but there are gaps and the query excludes these. We still want to show the hours that do not have activity and display a zero so tha...

Password protected PDF/Excel reports using SQL Reporting services

I am generating a reports using SQL Reporting services 2005. I need to protect the protect the reports(pdf and excel) with the password while the user is exporting the report to to excel or pdf. Is there any way to protect the report. ...

Group repeated rows in TSQL

I have the following table and data in SQL Server 2005: create table LogEntries ( ID int identity, LogEntry varchar(100) ) insert into LogEntries values ('beans') insert into LogEntries values ('beans') insert into LogEntries values ('beans') insert into LogEntries values ('cabbage') insert into LogEntries values ('cabbage') insert...

Problem inserting string or NULL into SQL Server database

I'm having trouble coming up with the proper syntax for allowing either a string or a NULL to be passed to the database. Here's my code: string insertString = String.Format( @"INSERT INTO upload_history (field1, field2, field3) VALUES ('{0}', '{1}', '{2}')", varField1, varField2, varField3); I used single quotes around th...