tsql

Insert into replicated table fails - identity range check

I'm trying to insert a few thousand rows into a table in a database that is replicated across two servers. From either the publisher or the subscriber, I get the same error: Msg 548, Level 16, State 2, Line 1 The insert failed. It conflicted with an identity range check constraint in database 'XXX', replicated table 'dbo.NODE_ATTRIB_RSL...

SQL Server - Rewrite trigger to avoid cursor based approach

If I have table Test with two columns num1 and num2 and the following trigger on it which just increments num2 on inserts of num1: DECLARE @PROC_NEWNUM1 VARCHAR (10) DECLARE @NEWNUM2 numeric(20) DECLARE my_Cursor CURSOR FOR SELECT num1 FROM INSERTED; OPEN my_Cursor FETCH NEXT FROM my_Cursor into @PROC_NEWNUM1 WHILE @@FETCH_STAT...

T-SQL fulltext catalog search with freetext

I have a fulltext catalog for an indexed view. Problem: I want to search with the function 'FREETEXT' all words which contains the search term. But the result doesn't return any entries... but one entry must be the word 'freightcosts' If the search term = 'freightcosts', the result is 'freightcosts'? Example: SELECT [Description] ...

statement "USE @dbname" doesn't work, why? How to do that?

I've got this t-sql snippet: DECLARE @db_name varchar(255); SET @db_name = 'MY_DATABASE'; -- assuming there is database called 'my_database' USE @db_name -- this line ends with error "Incorrect syntax near '@db'." But USE with variable (third line of snippet) doesn't work. Why it doesn't work? ...

T-SQL Check Why Record Is Missing

Hi, If you've got a very complicated SELECT statement and some records aren't included because of a join, what is the easiest way to debug this and find the reasons why? ...

Filtering SQL Rows

Table Schema ID Activate_Date InActivate_Date 1 2009-12-18 10:25:19.470 2010-01-13 08:32:30.130 2 2009-12-18 10:25:19.470 2010-01-13 08:32:30.253 3 2009-12-18 10:25:19.470 2010-01-13 08:32:30.363 4 2009-12-18 10:25:19.470 2010-01-13 08:32:30.583 5 2009-12-18 10:25:19.470 2010-01-13 08:32:...

TSQL: Datetime overlapping and interval values

Need help to create a query for this. Start | End 2009-01-01 06:00:00 | 2009-01-01 14:00:00 2009-01-01 06:00:00 | 2009-01-02 06:00:00 2009-01-02 07:00:00 | 2009-01-02 08:00:00 2009-01-03 06:00:00 | 2009-01-03 14:00:00 2009-01-03 09:00:00 | 2009-01-03 11:00:00 2009-01-04 22:00:00 | 2009-01-05 06:00:00 2009-01-05 01:00:00 | ...

SQL Server Integration Services SSIS 2005 - How do I see all the rows in a data viewer?

I have a data viewer attached to a transformation to show me the data as a grid. At the bottom is says total rows 22002, rows displayed 9964. How do I get it show me the remaining rows? I've tried clicking and right clicking on everything! ...

Write a T-SQL query that filters records containing NCHAR(2028)

My ultimate goal is to write a sql script that selects data from a particular table where a nvarchar(max) column contains the character NCHAR(2028). But the obvious: select * from tablename where columnname like '%' + NCHAR(2028) + '%' returns all rows. ...

SQL NOT IN Clause

I have a query which is not working as expected Q1: SELECT id, name FROM vw_x WHERE id NOT IN (select pid from table_x) GROUP BY id, name Having max(c_date) > GETDATE() Q2: SELECT id, name FROM vw_x GROUP BY id, name Having max(c_date) > GETDATE() Q1 is not returning anything even though i know those ids are not in table_x Q2 run...

SQL server - Select all items with a date on the previous month

Hi Guys, I have a table in my SQL Server database called "items" which has a column called "dateFinished". I have a script that will run on the 1st day of each month which needs to select all items that finished in the previous month. So, for example, on the 1st February it will need to select all items where the dateFinished is great...

SQL Server creating a temporary table from another table

I am looking to create a temporary table which is used as an intermediate table while compiling a report. For a bit of background I am porting a VB 6 app to .net To create the table I can use... SELECT TOP 0 * INTO #temp_copy FROM temp; This creates an empty copy of temp, But it doesn't create a primary key Is there a way to crea...

best way in producing a master script for SQL

hi, i want to extract specific database tables & stored procedures into one master script. Do you know any software that can help me do this faster? I've tried using the SQL Database publishing tool, but it's not that efficient since its gathering tables that I didn't select. ...

Determine that a database is currently mirroring or not?

Is there a T-SQL script to determine a database is currently mirroring or not? Is there a way to determine its partner? Thank you very much. ...

problem with IN and LIKE in SQL when arguments contain special characters for a language

Hello, I’ve got such a KeyWord table (MS SQL): KeyGuid Qualifier PrimitiveKey DA7E4E27-FDE5-4D43-A365-8A789164A816 tit kirkäna EED58875-FE41-4A18-A93C-A44AA62CEEEE htit kirkänbh A0EB795E-EE23-4990-BAB9-897C93C70CE3 htit kirkänah F7F4632B-AC82-4DEB-B966-BBA8EF4D2C9E tit kirkänb C0EB795E-EE23-4990-BAB9-897C93C70CE3 nam kirkänas E2F...

How do I get a proper weighted average date in SQL

I use this query to get my average date: CONVERT(DATETIME, AVG(CONVERT(FLOAT, ChargeOffDate))) as [Average C/O Date] Which correctly give me the date '2003-08-12 14:17:22.103'. When I use this query to get the weighted average date CONVERT(DATETIME, SUM(CONVERT(FLOAT, ChargeOffDate) * FaceValue) / SUM(FaceValue)) I get a date like...

Finding the SUM of values of a column of all records in sql 2005

I want to find the SUM of values in a column weight. I want this sum for all records that are identified with a common value in one of the columns name. Further, I want to consider only those records that have a certain value in the column type. name ...

Using T-SQL to get contents of backup media

Hello all, In SQL Server Management Studio (I have 2008), I can see the contents of the media i have backed up to, be it disk or tape. I can see information such as what files it currently includes, the dates they were backed up, etc... Is there a way to do this in T-SQL? I would like to specify a device (which is linked to a fil...

SQL If "something" select count

The output that comes from a custom view of mine is as follows... Col1 Col2 Col3 Col4 xxxx Cake 1 1* Cake xxxx 2* 1 xxxx Cake 2 0* xxxx Cake 0 0* Cake xxxx 2* 0 Cake xxxx 2* 0 and what i would like to sum is... For every row, if the word Cake is found in Col1, t...

Make a one line data to a table in SQL

Hi all There is a record like SWD Lead QA Lead PD Lead Business Manager AAAA BBBB CCCC DDDD I want to use T-SQL to get a result like below with the column name SWD Lead AAAA QA Lead BBBB PD Lead CCCC Business Manager DDDD Does anyone know how to do it ? Best Regards, ...