sql

how to add line breaks in a query (informix)?

I need to do a query that updates text with line break, I tried using \n but it inserts "\n" literally. Example: update table set text = "first line\nsecond line" I want it to show that text as: "first line second line" and not as "first line\nsecond line". When I do this with .net it works, but not on a stored procedure Does an...

PL/SQL - caching two resultsets into collections and joining them together?

I have two very large tables and I need to process a small resultset from these tables. However, processing is done in several functions each and function must do some joining in order to format the data in proper way. I would definitely need to cache the initial resultset somehow so it can be reused by the functions. What I would like ...

MySQL: How can I condense this verbose query?

Here is my schema: Suppliers(sid: integer, sname: string, address string) Parts(pid: integer, pname: string, color: string) Catalog(sid: integer, pid: integer, cost: real) Primary keys in bold. Here is the MySQL query I'm working with: -- Find the sids of suppliers who supply every red part or supply every green part. -- this isn't...

SQL: Select from many-many through, joined on conditions in through table

Can't get my head around this... I have 3 tables like this: Computers --------- Id Name ComputerLogins -------------- Computer_Id User_Id NumberOfLogins Users ----- Id Name Computers "have and belong to many" Users "through" ComputerLogins. Sample data: Computers: Id Name 1 "Al...

Agregate SQL query with maximun number of rows to take into account

My head is hurting trying to figure out a SQLquery. I have a table of vote data with team_id, ip_address and date_voted fields and I need to return a count of votes for each team_id but only count the first 10 rows per IP address in any 24 hour period. Any help will be greatly appreciated and may stop my head from pounding! ...

sql update records compared to records from another table

should be fairly simple. i have 2 tables. one of them has table1(ID,name,other_id) and the other table has table2(id,name,group,..) i want table1.other_id to be same as table2.id based on the data in the name fields on both tables. ...

Retaining NULLs in numerical columns using SSIS Import/Export Wizard?

I am having a problem uploading data from tab-delimited flat files (TSV files) into SQL Server 2005 using the SSIS Data Import wizard. I did not experience this problem using the equivalent procedure in SQL Server 2000, and I have checked that the internal structure of the files I am trying to import is unchanged since well before the SQ...

SQL select row into a string variable without knowing columns

Hello, I am new to writing SQL and would greatly appreciate help on this problem. :) I am trying to select an entire row into a string, preferably separated by a space or a comma. I would like to accomplish this in a generic way, without having to know specifics about the columns in the tables. What I would love to do is this: DECLAR...

SQL Server DDL script to append (or drop) the same set of columns for every table in a database?

How would one write a sql server DDL script that can: For each table in database: add column CreatedBy add column CreateDate add column UpdatedBy add column UpdatedDate Also, if the particular column already exists on the table, just skip that column. Also, the reverse of it, for each table, drop those 4 columns. ...

sql server stored proc times out and query does not time out, why ?

I have a stored proc on sql server 2008 that excepts a int parameter. It does call other stored procs and have nested quires. the problem i am facing is when i run the procedure from SQL server management studio it does not execute and times out. If i run the queries in side the stored proc separately in another SQL server management s...

Opening SQL command from SQL Server 2008?

I cannot find where the sqlcmd is? i just want the prompt. please help! ...

Best way to query different database engines in a uniform way?

I work on a C# client application (SlimTune Profiler) that uses relational (and potentially embedded) database engines as its backing store. The current version already has to deal with SQLite and SQL Server Compact, and I'd like to experiment with support for other systems like MySQL, Firebird, and so on. Worse still, I'd like it to sup...

Reaching child records in a SQL Server table

Out of my lack of SQL Server experience and taking into account that this task is a usual one for Line of Business applications, I'd like to ask, maybe there is a standard, common way of doing the following database operation: Assume we have two tables, connected with each other by one-to-many relationship, for example SalesOderHeader a...

Oracle SQL: Joining at most one associated entity

I have tables Building and Address, where each Building is associated with 0..n Addresses. I'd like to list Buildings with an associated Address. If a Building has several entrances, and thus several Addresses, I don't care which one is displayed. If a Building has no known addresses, the address fields should be null. This is, I want ...

SQL - Conditional WHERE clause

I have a SQL Server 2005 stored procedure that performs a query. This stored procedure takes in three parameters. The parameters are as follows: @StateID as int, @CountyID as int, @CityID as int These parameters are used to query a list of customers. I want to basically do a "AND" if the parameter value is not null. However, I ...

Poor response when parameters are variables in sql udf

Have an inline sql udf When called with variable DECLARE @COMNO CHAR(3), @CUNO VARCHAR(6) SELECT @COMNO='020',@CUNO ='000022' select * from ftItemsOfCustomer(@COMNO,@CUNO) TAKES 9 SECONDS, WHERE AS select * from ftItemsOfCustomer'020','000022') TAKES ONLY A SECOND ! WHY AND HOW CAN I RESOLVE THIS TO PERFORM WITH EQUAL RESPONSE ...

LINQ Query - Odd Result - OrderBy

Hello, I have the following code: int pageNumber = 0; int pageCount = 10; int numberOfRecords = 10; var query = V_ers_notice.Skip(pageNumber * pageCount).Take(numberOfRecords ); return query.OrderByDescending(id => id.DOC_DATE).Select(ERSNoticeMap.DataToObject).ToList()); The ERSNoticeMap code is as follows: public class ERSNo...

iBatis circular references question

I have an Office object and a Device Object. An Office has a device and a device belongs to an office. So, obtaining an Office object should populate Office.Device reference and a Device object should have an Office object where it belongs. It's a circular reference I suppose. I'd like to do this in iBATIS, but I can't figure out how ...

SQL IErrorInfo.GetDescription error.Brackets not working

I have the following code. I tried putting brackets around all the tables and parameters with no luck. The query works in Access though. Dim cn As OleDbConnection Dim cmd As OleDbCommand Dim str As String Dim dr As OleDbDataReader DataGridView1.Rows.Clear() Try cn = New OleDbConnection("Provider=microsoft....

Insert 2 rows that are related in both directions in SQL

I have two tables kinda like this: // Person.Details Table: PersonID int [PK] | EmployeeCreatorID int [FK] | FirstName varchar | OtherInfo... // Employee.Details Table: EmployeeID int [PK] | PersonID int [FK] | IsAdmin bit | OtherInfo... Each table is related to the other: [Employee.Details.PersonID]===>[Person.Details.PersonID] AND...