tsql

A lot of Many To Manys

Hi All, I am working on a DB Structure and it seems like I have ended up with a lot of many to many tables. The reason I have am getting so many of them is that my base table is items and each item can have multiple occurrences of the search criteria that will be surfaced to the users. So I normalized all of the search criteria and us...

Good questions to determine a candidate's level of C# and t-SQL knowledge?

Possible Duplicate: Good C# Interview Questions for a Senior Dev Position What questions would you ask, specifically? If you were looking for a candidate with "strong t-SQL and C#" skills. The position is not a senior position, but requires an experienced web developer. What knowledge would you be looking for? ...

In SQL Server 2005, is it possible to set transaction isolation level on a per-user basis?

In SQL Server 2005, is it possible to automatically set transaction isolation level to, say, read uncommitted an a per-user basis? (So for instance, if I set such a login option for user Fred, Fred wouldn't have to remember sprinkle his select statements with NOLOCK hints or remember to add in a set transaction isolation level statement...

Sql server 2005 :How to Import objects of a schema to another

Hi all, I have created several objects (Tables,Stored Procs, functions etc.) under a new schema (x) Now I want to import them to DBO schema. How can I do that.. Thanks ...

How can I get the message for a @@Error number?

You would think it would be easy to find out what 1 means, but google is not being helpful (I would guess that it does not see the @@ part and error is to generic. MSDN (at least on the @@Error page and Concept page) is also unhelpful. Any help here? ...

No rows in MSDB.dbo.sysmail_faileditems

Initially I was getting a "no SELECT privilege" error when attempting to query contents for a report I need to create. So we granted DatabaseMailUserRole in MSDB to my account - I see columns, but none of the data we know to exist. What am I missing that needs to be done for my account to see the data? ...

How can I tell why my query is taking so long?

I have a query that is taking a lot longer then usual, and I cannot tell if it is stuck. The query is something like this: INSERT XXXXXX WITH (TABLOCK) SELECT * FROM YYYYYY with (NOLOCK) WHERE ZZZZZZZZ = 1 This will insert hundreds of millions of rows. I have an index on ZZZZZZZZ. There are no blocking sessions. When I check sys.d...

sp_executesql causing my query to be very slow

I am having some issues when running sp_executesql on a database table. I am using an ORM (NHibernate) that generates a SQL query that queries one table in this case. This table has about 7 million records in it and is highly indexed. When I run the query that the ORM spits out without the sp_executesql, it runs very quickly and pro...

T-SQL Case statement utilizing substring and isnumeric

I have a T-SQL stored proc that supplies a good amount of data to a grid on a .NET page....so much so that I put choices at the top of the page for "0-9" and each letter in the alphabet so that when the user clicks the letter I want to filter my results based on results that begin with that first letter. Let's say we're using product na...

This SQL query is not working for me please help

I have a poorly normalized set of tables and am trying to correct this issue. The DB is MS SQL 2005. Table1 has an id field (record ID), a mainID field (person ID) and a sequence field (and int that determines the sort order) Table2 has its own id field and a copy of the id for the first record by a person (sequence = 1). I've added ...

LIKE work-around in SQL (Performance issues)

I've been reading around and found that using LIKE causes a big slowdown in queries. A workmate recommended we use Select Name From mytable a.Name IN (SELECT Name FROM mytable WHERE Name LIKE '%' + ISNULL(@Name, N'') + '%' GROUP BY Name) in lieu of Select Name From mytable a.Name LIKE '%' + ISNULL(...

How can I post updates (commits) in oracle db to SQL Server 2005

We have an application (BaaN) on Oracle Database. We also have an application that is on SQL Server 2005 which uses Oracle (BaaN) contents. Currently we cache all contents of the Oracle DB to SQL Server nightly through linked server from SQL Server to Oracle. Thought of using a trigger on Oracle db tables to write contents to Oracle t...

How do I SELECT an un-referenced row from a table and lock it?

Hi there, I have a table of chalets where a chalet is referenced by an account... CHALET ------ int ChaletId PK int Berth ACCOUNT ------- int AccountId PK int ChaletId FK The chalets start off un-referenced. When a user buys a chalet the code needs to find an unreferenced chalet and assign it to a newly created account. I think that...

SQL Query Group By Datetime problem?

I have this SQL query: SELECT DISTINCT [BatchCode] ,SUM([Quantity]) as 'Created' ,[TotalQuantity] ,[Status] ,[Destination] ,[DateCreated] ,[CreatedBy] FROM [FGIS].[dbo].[DropshipPackinglist] GROUP BY BatchCode, TotalQuantity, Status, Destination, CreatedBy, ModifiedBy...

Capturing multiple error messages from a single statement.

I am running a batch of statements on several columns and tables and want to retrieve information on what errors occur. The statement is a type change (varchar to nvarchar) and when it fails, it seems to return 2 errors. Msg 5074, Level 16, State 1, Line 1 The object 'DF_XXX_YYY' is dependent on column 'YYY'. Msg 4922, Level 16, State ...

Is there anyway to reference the collection of parameters passed to a stored procedure, without referencing each one by name?

Is there any way to reference the collection of parameters passed to a stored proc, without referencing each one by name? The context here is error logging. I'd like to develop a generic CATCH clause, or sub-clause, that grabs all parameter values as well as other error and execution info and logs it to a table (one or more). The basic...

SQL to calculate distinct count for a desired table.

id1 id2 year State Gender ==== ====== ====== ===== ======= 1 A 2008 ca M 1 B 2008 ca M 3 A 2009 ny F 3 A 2008 ny F 4 A 2009 tx F This is the table i have, I need to find the total No of distinct Count in this t...

Tutorial for speeding up SQL queries?

Is there a good tutorial out there how to speed up/refactor SQL Queries? I googled a bit, but did not find anything useful. Thanks :-) ...

How to add a new identity column to a table in SQL Server?

Hello everyone, I am using SQL Server 2008 Enterprise. I want to add an identity column (as unique clustered index and primary key) to an existing table. Integer based auto-increasing by 1 identity column is ok. Any solutions? BTW: my most confusion is for existing rows, how to automatically fill-in new identity column data? thanks in...

Using variable to TSQL + XQuery

All, I have the following code: --xml is already declared and populated with an xml document SELECT ent.query('TradeId').value('.','VARCHAR(10)') TradeId FROM @xml.nodes('//table/trade[1]') Col(ent) How can I have the expression //table/trade[1] as a variable so I can increase the [1] in a loop ? For example I wo...