sql-server

XML query against SQL Server SSIS DataProfiler xml file in Powershell does not work. Help?

Hi, I am trying to query out the attribute values from the xml file attached below. Specifically, I am trying to get the Name, SqlDbType etc. attribute values that are in the "Column" Element Node under"ColumnNullRatioProfile" Node. The xml output file comes as a part of the SQL Server 2008 SSIS DataProfiler Task. My goal is to use Pow...

Should 0xFF "END OF FILE" be in the fulltext index?

Hi, I recently found out that you can get information about the index of a table using sys.dm_fts_index_keywords (SQL Server 2008 Express). I was surprised when I saw that 0xFF "END OF FILE" has the most occurrences of all the terms in the index (document count = 2730). Is that normal? What about disk space: Does the index store referen...

trigger in sql server 2000

I have a trigger that supposed to update log out time[generate random log out time within an hour of log in time, seconds have to differ too], how do I achieve that functionality, please help here is my trigger so far: USE TestDB GO CREATE TRIGGER AfterInsertTG ON dbo.usage_reports_Dummy2 AFTER INSERT AS DECLARE @pk_id as int, @mem...

How do we tell sqlcmd to continue "on error" with next batch?

Any ideas on how to accomplish this? USE [db_name] BEGIN TRANSACTION ...TONS OF INSERTS COMMIT; RAISERROR (..) WITH NOWAIT; //If error continue with next batch BEGIN TRANSACTION ...TONS OF INSERTS COMMIT; RAISERROR (..) WITH NOWAIT; ... ...

What is the data type of "select 123.866" in SQL server 2005?

If I just write something like select 10.00; What type does this give me? Here's a test I ran, to test the binary representation of these types. The big surprise here is that none of the casts actually match the first row! select cast(123.866 as binary) union all select cast(cast(123.866 as real) as binary) union all select cas...

Grouping/aggregating SQL results into 1-hour buckets

Similar to this question, I need to group a large number of records into 1-hour "buckets". For example, let's say I've got a typical ORDER table with a datetime attached to each order. And I want to see the total number of orders per hour. So I'm using SQL roughly like this: SELECT datepart(hh, order_date), SUM(order_id) FROM ORDERS GRO...

Delete SQL looping

I want to keep only 1000 entries for each clientid. The code below does what I want but does not loop through the clientid, instead keeping 1000 total of any of the clients. Is there a way to do this in sql? I was told i need a cursor, but I am hoping not. SQL 2005 DECLARE @ids TABLE ( id int ) DECLARE @clients TABLE ( clientid varc...

Best and Quick Way to Learn T-SQL on Online

Hi, I want to learn T-SQL but there are so much kinda useless documents around internet. I've been searching tutorials but either most of them are not for beginners or cut off the tutorial at the best part. I wanna learn it from start to advanced so could you guys please show me a website or something where I can learn it best. Thanks...

What is the recommended setup.ini for SQL 2000 MSDE install?

What is the recommended setup.ini for SQL 2000 MSDE install? So far, I use: [Options] SAPWD=comp1exPa$$word SECURITYMODE=SQL INSTANCENAME=MSSQLSERVER DATADIR ="C:\Databases" COLLATION=SQL_Latin1_General_CP1_CI_AS ...

Delete records which are considered duplicates based on same value on a column and keep the newest

I would like to delete records which are considered duplicates based on them having the same value in a certain column and keep one which is considered the newest based on InsertedDate in my example below. I would like a solution which doesn't use a cursor but is set based. Goal: delete all duplicates and keep the newest. The ddl below ...

db string length errors and NHibernate

In a SQL server db I have a Name column in the Departments table, with nvchar(25) not null, unique. I test to see what happens if I try and save a Department with a Name that is bigger than that and get an "NHibernate.Exceptions.GenericADOException" making it clear that ""String or binary data would be truncated". So far, so good. In an...

SQL Server IF NOT EXISTS Usage?

Ok, so my schema is this: Table: Timesheet_Hours Columns: Timesheet_Id (PK, int) Staff_Id (int) BookedHours (int) Posted_Flag (boolean) This is an extremely simplified version of the table, but it will serve for the purposes of this explaination. Assume that a person can only ever have one timesheet record. What I'm trying to do i...

SQL Server error on update command - "A severe error occurred on the current command"

Running the following query in Management studio update table_name set is_active = 0 where id = 3 gives the following error, Msg 0, Level 11, State 0, Line 0 A severe error occurred on the current command. The results, if any, should be discarded. Msg 0, Level 20, State 0, Line 0 A severe error occurred on the current command. Th...

SQL Query - Delete duplicates if more than 3 dups?

Does anyone have an elegant sql statement to delete duplicate records from a table, but only if there are more than x number of duplicates? So it allows up to 2 or 3 duplicates, but that's it? Currently I have a select statement that does the following: delete table from table t left outer join ( select max(id) as rowid, dupcol1, dup...

How to solve insert/delete deadlock on non-clustered index?

I got a deadlock problem and I found that it's caused by two stored procedures that is called by different threads (2 called web services). Insert sp that insert data in X table. Delete sp that delete data in X table. Moreover, I got result that told me about deadlock happened in non-unique and non-clustered index of X table. Do you ...

What is an MDF file

Is this like an "embedded" database of sorts? A file containing a built in database? ...

DTS for SQL Server 2005 Express Edition

What did Microsoft rename DTS to for SQL Server 2005 Express Edition? Where is the download link to the SQL Server 2005 Express Edition DTS utility? i've been searching for half an hour, and i can't find a definitive answer. i need to import data from a data source into an SQL Server 2005 Express Edition database. ...

Clustered Indexing

Does Clustered index needs one extra table to sort/keep the rows data? When it does the sorting , on each Insert or delete statement or when ? How clustered index store data and how it is different from Non-clustered one. ...

SQL to determine minimum sequential days of access?

The following User History table contains one record for every day a given user has accessed a website (in a 24 hour UTC period). It has many thousands of records, but only one record per day per user. If the user has not accessed the website for that day, no record will be generated. Id UserId CreationDate ------ ------ ----...

How can I get installed sql server instances??

Hi Guys, How can I get installed sql server instances from registry? How I can determine default instance?? Thanks Rajesh ...