sql

Table design for cyclic dates

hello, In my application users should be able to define dates when they are available. Ie. user joe may define he's available: - at every monday, wednesday and sunday between 15:00 and 17:00 from 1.09.2009 to 15.11.2009. - at 2.09.2009 between 12:00 and 14:00 and so on... Dates may be defined maximum 1 year in future. Users may add, e...

Get Updated Row

I have a query that updates one record, and only one record. Is there are way to get the Id updated in the same query such as Select ScopeIdentity when inserting. UPDATE Task SET MyTime = GetDate(), MyUserId = @userid FROM (select top 1 table where SomeStuff) Select Lastrow that just got updated. ...

SQL Server : alias is ignored in Order by

We have two tables in our application that both have a ShowOrder column.We are using NHibernate in our application and using HQL we join these two tables ordered by ShowOrder of first table and second table respectively. Here's a simplified version of my query : SELECT pr.Id as Id,pr.Title as Title, pr.ShowOrder as ShowOrder FROM Proce...

Merging two SQL SELECT statements

I need to merge two SELECT statements. There are two tables in my database, where table A consists of two fields; Type and Counter. Table B consists of two fields; Source and destination. Table A has three items; { 1, 5000 }, { 2, 10000 } and { 3, 15000 }. ({Type, Counter}) Table B has two items; ...

Someone created two identical accounts on my website at the exact same time. How is it possible?

I can't believe this - someone actually created two accounts on my social networking website using the same email even though there are both server sided as well as client sided validation checks that prevent such a thing from happening. But get this the time noted in the creation of both the accounts are exactly the same time. For some...

stsadm addcontentdb - add content database from sp1 to sp2 environment?

I'm trying to add a content database from a sp1 environment to a sp2 environment, but I am getting the error, Login failed for user "username". Reason: Not associated with a trusted SQL Server connection I've tried all accounts, from Farm Admin, Web app account, to SQL Admin Method's are both true from here: http://support.microsoft....

ORA-01756: quoted string not properly terminated

please let me know the issue with following script (sql,oracle 10g) 1 DECLARE @colname AS NVARCHAR(50) 2 DECLARE @tablename AS NVARCHAR(500) 3 DEClARE @query AS NVARCHAR(500) 4 SET @colname = 'select wk_units1 from cnt_sls_dm.fct_sales_summary' 5 SET @tablename = 'SELECT tablename from dmi_user.fct_sales_meta' 6 set @q...

Unque numbering rows in SQl Server for duplicate values

Is it possible to re-write this query to restart numbering when the UName changes so that my result set is: 1 FerrieC 2 FerrieC 3 FerrieC 1 GrayD 1 TimneyA 2 TimneyA SELECT Row_Number() OVER (ORDER BY u.UName) as RowNumber , u.UName FROM ( SELECT 'Ferriec' As UName UNION ALL SELECT 'Ferriec' As UName UNION ALL SEL...

How can I optimize these queries?

Consider the following code snippet: $beat = date('B'); // 1 beat = 86.4 seconds, 1000 beats = 1 day $total = 'SELECT COUNT(id) FROM ads WHERE featured = 1;'; // number of featured ads $current = 'SELECT * FROM ads WHERE featured = 1 ORDER BY id ASC LIMIT 1 OFFSET ' . ($beat % $total) . ';'; // current featured ad Basically this cycl...

Does parameter passing order affect the caching of query plans?

Does the order in which parameters are passed to a stored procedure affect the caching of query plans, or cause any other sort of extra processing overhead? My theory is "no" for the query plans, and any processing overhead required to re-order the parameters is negligible, but I'd like to find some information to back it up. ...

Passing BLOB/CLOB as parameter to PL/SQL function

I have this procedure i my package: PROCEDURE pr_export_blob( p_name IN VARCHAR2, p_blob IN BLOB, p_part_size IN NUMBER); I would like for parameter p_blob to be either BLOB or CLOB. When I call this procedure with BLOB parameter, everything is fine. When I call it with CL...

sql server helper stored procedure or utility for alter table alter column IDENTITY(1,1)

I wanted to modify a column in a sql server 2005 table to IDENTITY(1,1) Incidentally this table is empty and the column to be changed is a primary key. This column is also a foreign key for two other tables. After googling I found that you cannot use Alter table syntax to modify a column and make it an indentity column. Link #1 : How...

multiple criteria search

I have multiple tables with Customer data (ex Customer Name, Customer Contact Name, Customer Service Item etc). I need to enable search on these multiple columns across tables. Then I have to use the search result to pull Customer information (I need Customer ID, or Customer Name). What is the best way to do this? Possible Solution...

Left join with complex join clause

Hi, I have two tables and want to left join them. I want all entries from the account table, but only rows matching a criteria from the right table. If no criteria is matching, I only want the account. The following does not work as expected: SELECT * FROM Account a LEFT JOIN Entries ef ON ef.account_id = a.account_id AND (ef.entry_...

Is there any difference between using innerjoin and writing all the tables directly in the from segment?

Do these two queries differ from each other? Query 1: SELECT * FROM Table1, Table2 WHERE Table1.Id = Table2.RefId Query 2: SELECT * FROM Table1 INNER JOIN Table2 ON Table1.Id = Table2.RefId I analysed both methods and they clearly produced the same actual execution plans. Do you know any cases where using inner joins would work in...

How bad is my query?

Ok I need to build a query based on some user input to filter the results. The query basically goes something like this: SELECT * FROM my_table ORDER BY ordering_fld; There are four text boxes in which users can choose to filter the data, meaning I'd have to dynamically build a "WHERE" clause into it for the first filter used and the...

Show only most recent date from joined MySQL table

I have 2 tables, a "document" table and a "content" table. They look like this (simplified): document table: docID docTitle content table: contentID docID dateAdded content For every content change, a new record is inserted into the "content" table. This way there is a complete history of all changes. I would like to get a list of al...

Excessive reserved space on SQL Server

We have a database running under MSDE (SQL 2000, service pack 4) that is reserving massive amounts of excess space. Using sp_spaceused for each table gives a total reserved size of 2102560 KB, a data size of 364456 KB and an unused size of 1690760 KB (i.e. reserving nearly 4 times the used space). The worst culprits are tables that are f...

how do I select a column based on condition?

Hello, I have a variable called @status which I set before this select statement: Select ordr_num as num, ordr_date as date, ordr_ship_with as shipwith From order where ordr_num = @ordrNum I only want to select ordr_ship_with column if @status <> 'Cancelled', otherwise I want to select null for shipwith. How do I accomplish this? ...

Fluent NHibernate / NHibernate Mappings

I have a parent table and relationship table to find child parent relationship. I need to find child, parent and its siblings... EMPLOYEE_RELATION has columns EMPLOYEE_ID and PARENT_ID that saves the relationship. Here's what SQL looks like. How do I map this to Fluent NHibernate / NHibernate. select V1.PARENT_ID AS PARENT_ID, ...