sql

query execution plan : missing index

There are two tables that I join them together, one of them is a temp table and I create an index after creating the table. But it is said in the query execution plan above. what should I consider to convert all scan operations to seek operations? There are parts which are joins and where conditions... Regards bk ...

How can I delete from three tables with foreign keys?

I want to be able to choose a groupID and do a cascading delete through three tables which are found in a MS SQL server database. The tables look like the following: table 1 - GROUP ------------------------------------------- groupID | description | etc table 2 - MEMBER ------------------------------------------- memberID | name | et...

MS-Access: Replace "bracket"

Hi, In one of the ms-access table I work with we have a text field with a set size. At the end of this field there is some extra code that varies depending on the situation. I'm looking for a way to remove one of these code but even when the last part is truncated by the field maximum size. Let's call the field "field" and the code I'm...

Function to return valid date from varchar field

We have a function that pulls the date from the first 8 characters of a string. Because of the way this system was written, the users are told they have to enter the date in an 8 character format in the field. For example, 12/06/10 must be entered. The way the original function was written, 12/6/10 or 12/06/2010 would generate a wrong...

Replace id with string in SQL view

I have two tables... groupid membership_list managerid ------------------------------------- 0 /0//1//2/ 2 1 /2/ 2 userid username ------------------ 0 ben 1 tom 2 dan I'd like to display a table to for example the user 'ben' that is a list of the groups they are a ...

osql -S not giving me expected results

I'm trying to write a program in Java that uses osql to generate a list of databases on a server. My code is as follows: public Object[] findDataBases(String server, String user, String passwd){ str = new String[] {"cmd.exe", "/c", "osql", " -S ", server, " -U", user, "&&", "-P ", passwd, ...

Create IBM DB2 CHECK for date greater or equal current date

I'm trying to create a table with a field that has a starting date, I want to put in a check to mkae sure that a date before today cannot be entered in. This is the code i have so far for that table CREATE TABLE client_service ( NHS_num Varchar(10) NOT NULL, service_id Integer NOT NULL, starting_date Date NOT NULL CHECK(star...

SQL Server Reset Identity Increment for all tables

Basically I need to reset Identity Increment for all tables to its original. Here I tried some code, but it fails. http://pastebin.com/KSyvtK5b actual code from link: USE World00_Character GO -- Create a cursor to loop through the System Ojects and get each table name DECLARE TBL_CURSOR CURSOR -- Declare the SQL Statement to cursor t...

When should database synonyms be used?

I've got the syntax down but I'm wondering if somebody can provide an illustrative use case where database synonyms are very useful. ...

select from table with result of another sql

Is it possible? tag_table : tag        postid aa          22 bb          26 cc          28 post_table : id          content 26            abc 28            cdf 22            fds and I wanna select from post_table with result of search in tag_table my script : first SELECT postid FROM `tag_table` WHERE `tag` L...

In Doctrine ORM, how can I sum seconds to a timestamp field?

I have a starts_at field that keeps a timestamp with the moment something starts. Also, I have another field seconds_long that represents the amount of seconds that the event lasts. I need to select all unfinished events but I just can't find a way to sum the starts_at and seconds_long fields. I first tried to sum them, expecting Doctri...

Returning partial address matches and mismatch position using L2S or SQL

I need to implement a method that takes an address split up into individual parts and returns any matching items from an address table. If no matches are found, I want to be able to return a value indicating where it failed. Each input param has a corresponding field in the table. The signature would look something like this: List<Add...

unable to search using timestamp in mysql

I have created a timestamp field in mysql, where the date gets stored as 06/01/2010 07:55:40 Now if I try to search anything using a query like this : select StartTime from results where timestamp(StartTime) = "30/09/2009" it does not work. even I cannot use this : select * from results where StartTime between "06/01/20...

id columns or clustered primary keys/database consistency

If I had a table with the columns: Artist Album Song NumberOfListens ...is it better to put a clustered primary key on Artist, Album, and Song or to have an autoincrementing id column and put a unique constraint on Artist, Album, and Song. How important is database consistency? If half of my tables have clustered primary keys and t...

SQL Record Search But Field is Sometimes NULL?

Hi, I am trying to do a SQL query to see if an Address already exists in my database. My addresses are structure like this: line1 line2 line3 city state zipcode country Sometimes line2 and line3 are NULL values in my database. I am using .NET TableAdapter and DataTable to make my query. When I try to pass in my line2 parameter (@lin...

How do I view the SQL generated by SubSonic SimpleRepository ?

I've got this toy code, works fine, using MySQL var r = new SimpleRepository("DB", SimpleRepositoryOptions.None); var q = r.Find<User>(x => x.UserName == "testuser"); How do I view the SQL generated by that query ? ...

No query plan for procedure in SQL Server 2005

We have a SQL Server DB with 150-200 stored procs, all of which produce a viewable query plan in sys.dm_exec_query_plan except for one. According to http://msdn.microsoft.com/en-us/library/ms189747.aspx: Under the following conditions, no Showplan output is returned in the query_plan column of the returned table for sys.dm_exec_quer...

SQL: Unrolling a set

Suppose I have a set in SQL like this: Product | Quantity A 1 B 2 I want (in a single SELECT statement) to transform that to: Product A B B Can anyone point me towards (T-SQL preferably), a trick on how to do this? ...

SQL SERVER Project

My Application Database Without Project and without Source safe, i planned to make my DB to be as project and add it to TFS, but I have no idea how to script the stored procedures, Triggers, Views, Functions, and what is the best practice to Make Update Script for All My stored procedures, Triggers, Views, and Functions to My customers D...

T-SQL: IN statement in result Expression in CASE THEN expression

Is it possible to use IN in CASE..THEN ? WHERE record.field = CASE WHEN @flag = 1 THEN a WHEN @flag = 2 THEN IN (b, c) END Or how to rewrite such condition? ...