sql

Programmatically replacing linked server references with local database references in SQL Server stored procs?

As a part of a scripted procedure I'm trying to programmatically update references to linked servers in stored procs. We have several references like this:- SELECT foo, bar FROM [Server].[Database].dbo.[Table] Which I would like to translate to:- SELECT foo, bar FROM [Database].dbo.[Table] I would like to do this entirely programma...

Multiple FKs with ON DELETE CASCADE to the same table (MSSQL2008)

I'm running into the problem described by KB321843 and this question. Both only talk about MS SQL Server 2005 (or older), while I'm running 2008. I'd really had hope that this is fixed in recent versions, but it doesn't seem like it is. Could someone confirm this (or, better tell me how I could get it to work)? ...

How to check if the collection is empty in NHibernate (HQL)?

Hi! I have a following HQL query: SELECT s.id FROM stack s WHERE s.category is not empty Basically, s.category is a one-to-many join to another table (Category). I need to check whether the collection is empty or no. I can do it in c# code (just run through all of the Stacks and check if Stack....

dbml entity relationship problems

I'm creating a .dbml file from a database. My "property" table has foreign keys to the "county" table and to a "propertysource" table. When code is generated, Property.Source is defined as a PropertySource type, but Property.County is defined as an int, instead of a County type. I'm afraid I don't have the experience with LINQ to SQL t...

SQL Completely Empty Database

I am writing an install script that installs all tables, stored procedures, views, full text indexs, users ect. It all works fine if the user has all the correct permissions and the script runs from start to finish. However if the script dies somewhere midway through then it cannot just be run again. To accomplish this I want to basica...

SQLite: prevent duplicates

Hi, I would like to create a table to store device settings. The table has three rows: id, parameter_name and parameter_value. The table was created by executing the following query statement: DATABASE_CREATE = "create table DATABASE_TABLE (KEY_ID INTEGER PRIMARY KEY AUTOINCREMENT, KEY_NAME INTEGER not null, VALUE TEXT not null); an...

Sanity Check: Floats as primary keys?

I'm working with an old sql server 2000 database, mixing some of it's information with a new app I'm building. I noticed some of the primary keys in several of the tables are floats rather than any type of ints. They aren't foreign keys and are all unique. I can't think of any reason that anyone would want to make their unique primary ke...

How can I optmize a MAX date query relating to a other table entity

I`m having trouble trying to optimize this query with OVER (PARTITION BY ...) because the id field of the table containing the maxDate needs to relate to the other table. The working query is: SELECT maxReadDate, Equip.idProtocol FROM Equip, ( SELECT idEquip as idEquipTot, MAX(readDate) AS maxReadDate ...

Sqlite binding within string literal

Using sqlite3, if my query is SELECT * FROM table WHERE title LIKE '%x%' It will match strings that contain x. I want to make x a bindable parameter, like: SELECT * FROM table WHERE title LIKE '%x?%' However, this does not work since the '' form a string literal. Is there some way of escaping the ? within the literal? I understand th...

what characters should be escaped in sql string parameters

I need a complete list of characters that should be escaped in sql string parameters to prevent exceptions. I assume that I need to replace all the offending characters with the escaped version before I pass it to my ObjectDataSource filter parameter. ...

combobox and text input

I have to add a change event listener... I did add one something like this.... Private function Change(event:Event):void{ inputtxt.txt+=event.currentTarget.selectedIndex; vs.selectedChild=vsRef; } <mx:TextInput id="inputtxt"/> <mx:Button id="searchBtn" label="Search" change="Change(event)"/> This does nothing for me though...

MySQL joins, how to output relation "the proper way"

Hello, First of all, excuse my poor topic title. I simply have no idea how to formulate this question or what to Google after, so don't shoot me if this is something easy answerable. Assume I have the following tables: [AUTHORS] id, name [NEWS] id, item, author_id If I wanted to display a news item and output the corresponding autho...

Dynamic SQL to load images from a directory

Hi, New to this and very stuck! I am trying to load images into a database from a directory using the following code. When I execute the SP I get the following form the print statements I have included; USE [store] GO DROP PROCEDURE [dbo].[insert2img] /****** Object: StoredProcedure [dbo].[insert2img] Script Date: 07/08/2009 15:3...

How to know which stored procedures are running in an Oracle database?

I need to know which stored procedures are running. It's not an option to "mark" the stored procedures changing their source. Thank you very much. ...

SSIS Null Value Questions

I have a table with 5 string columns, all can be NULLs. After I read the data from this table, I want to convert any null values into empty strings. The reason is that I need to compare these columns with columns in another table of the same schema (using conditional split), and null values would cause the comparison to evaluate to NULL....

Problem using fn_listextendedproperty, Why does this query error on the fourth column on MSSQL2008

If you're just going to vote this down and not tell me how to do better, what's the point? How can I learn to make the question better if you vote -1 and not leave me a comment. select u.name, o.name, case (o.type) when 'S' then 'SYSTEM TABLE' else 'TABLE' end, (select convert(varchar(8000), value) from ::fn_listextendedpr...

converting from string to date in VBA and clearing old SQL data output for automation program

Hi, I am building a reconciliation tool via VBA that automates queries from my oracle database and a worksheet. When I run the query I want the user to input what ITEM (in this case pipeline) to query (the worksheet has many items) and the end/start dates. I am having trouble figuring out the following: 1) It is querying - if the value ...

What to use in SQL instead of a "Foreach" loop

I'm trying to write a stored procedure in SQL that will : Make a select query from table1 that will return multiple values Insert new values in table2 (1 new record in table2 for each record returned by the select on table1). I would use a foreach in C# but I know that SQL doesn't work that way. What's the correct way of doing this? T...

MySQL: get how many entrys for each id on each date?

I have a table with an associate_id and date fields. I want to get how many the associates have for each date. For example if this was my Table: date associate_id 2009-07-08 10 2009-07-08 113 2009-07-09 113 2009-07-09 113 I want results like this: date associate_id per_date 2009-07-08 10 1 2009-07-08 113 ...

Best way in Oracle to go from this data to this result

What is the best way in oracle to ge the following result set from a table like this: GROUP ID VALUE -------------------- 1 1 A 1 2 B 1 3 C 2 4 D 2 5 E 3 6 F 4 7 G 4 8 H ID Parent VALUE --------------------- 1 0 A 2 1 B 3 2 ...