Query Insert And Predicate On The Same Object

May 9, 2006

Hey all,

I've a querie which inserts into a table, while joining on it. Something like:

insert into table1
(columnA,
columnB
)
select (columnA,columnB)
from table2
where columnA NOT EXIST(SELECT 1 from table1,table2 where table1.columnA!=table2.columnA)

As a rule of thumb, I avoid subselects and negative logic. However, sql2k seems to pick the fastest execution plan using this query, using a left anti semi join on that subselect. My question is this; what are the repercussions of inserting into a table when sql2k has already picked a query plan based on its stats? Is deadlocking possible? I haven't been able to find any evidence one way or the other. My objects are several million rows, so I am expecting some sort of side effect.

Any help would be greatly appreciated.

Regards,
-Kilka

View 2 Replies


ADVERTISEMENT

SELECT Query With IN Predicate By Using SQLDATASOURCE

Apr 5, 2007

Thanks in advance....
 
Let me simplify what I'm trying to do.... 
 
Basically, I want to run the following query by using SqlDataSource.
      SELECT data FROM table WHERE row in ('one', 'two', 'three')
Simple enough....
 
So, here's my code.....which obviously doesn't work properly.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStr %>" SelectCommand="SELECT data FROM table WHERE row in (@username)">
          <SelectParameters><asp:ControlParameter ControlID="TextBox1" Name="username" PropertyName="Text" Type="String" /></SelectParameters>
</asp:SqlDataSource>
<asp:Label ID="TextBox1" runat="server" Text="'one', 'two', 'three'" Width="125px" Visible="True"></asp:Label>
 
Is my SelectCommand correct?  Thanks.
 
 

View 3 Replies View Related

Filter Query Using Free Text Predicate Contains For One Of Column That Have Dimensions Of Items

Oct 1, 2014

I am looking to filter the query using the free text predicate Contains for one of the column that have dimensions of the items. The query is something like

Select * from sampletable
where contains(filtercolumn, 'Near("*cm , *cm , *cm , *Kg.",10,True)')

Data in the filtercolumn is something like 64cm x 25cm x 35cm = 10Kg.

The query do not return any data.I also tried running the below query to see if cm* can be searcher for, but with no result again

Select * from sampletable
where contains(filtercolumn,, '"cm*"')

If I do something like below, it does return all columns that have 35cm within the text.
Select * from sampletable
where contains(filtercolumn,, '"35cm"')

View 1 Replies View Related

Predicate Vs Residual Predicate

Nov 20, 2006

hi ,
what is the definition and difference between predicate and residual predicate.
give me some examples..Basically the columns used in where clause are called as predicates. Am i right.

View 1 Replies View Related

Predict Query Gives 'DMPluginWrapper; Object Reference Not Set To An Instance Of An Object' Error

Mar 17, 2008



Hi,

I am trying to develop a custom algorithm. I have implemented and tested training methods, however I fail at prediction phase. When I try to run a prediction query against a model created with my algorithm I get:


Executing the query ...
Obtained object of type: Microsoft.AnalysisServices.AdomdClient.AdomdDataReader
COM error: COM error: DMPluginWrapper; Object reference not set to an instance of an object..
Execution complete


I know this is not very descriptive, but I have seen that algorith doesn't even executes my Predict(..) function (I can test this by logging to a text file)
So the problem is this, when I run prediction query DMPluginWrapper gives exception -I think- even before calling my custom method.

As I said it is not a very descriptive message but I hope I have hit a general issue.

Thanks...

View 3 Replies View Related

Cannot Insert Duplicate Key Row In Object

Jun 27, 2006

The following quote is the exact error message that I get when I attempt to create a pull subscription. The STAppointment is one of a 15 databases that need to replicate inorder for the application SalonTouch to run properly.

What is causing this error? Is it user rights? Is it a problem with sql2005? Am I missing a step? Is there a problem with the database I am working with? What else?

TITLE: New Subscription Wizard
------------------------------

SQL Server could not create a subscription for Subscriber 'D6LHWQ91PORTSUN9'.

------------------------------
ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

------------------------------

Cannot insert duplicate key row in object 'dbo.MSmerge_replinfo' with unique index 'uc1MSmerge_replinfo'.
The subscription could not be created.
The subscription properties table 'MSsubscription_properties' does not exist in the current database.
Changed database context to 'STAppointment'.
The statement has been terminated. (Microsoft SQL Server, Error: 2601)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.2047&EvtSrc=MSSQLServer&EvtID=2601&LinkId=20476

------------------------------
BUTTONS:

OK
------------------------------

View 3 Replies View Related

Cannot Insert Duplicate Key In Object 'dbo.RunningJobs'

Aug 21, 2006

I'm using SSRS 2005 on a Server 2003 machine.

Some of my reports run fine but others take a long time to run and sometimes fail with an http error 503.

After a report errror happens I find entries in the event log that says: cannot open a connection to the report server

When I look at the log files for Reporting services I see an error caused by a primary key violation on the Running Jobs Table:

Violation of PRIMARY KEY constraint 'PK_RunningJobs'. Cannot insert duplicate key in object 'dbo.RunningJobs'

Does anyone know why do I get such errors?

Bellow is the error message in the logs:

w3wp!library!6!21/08/2006-09:30:22:: e ERROR: Throwing Microsoft.ReportingServices.Diagnostics.Utilities.ReportServerDatabaseUnavailableException: The report server cannot open a connection to the report server database. A connection to the database is required for all requests and processing., ;
Info: Microsoft.ReportingServices.Diagnostics.Utilities.ReportServerDatabaseUnavailableException: The report server cannot open a connection to the report server database. A connection to the database is required for all requests and processing. ---> System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK_RunningJobs'. Cannot insert duplicate key in object 'dbo.RunningJobs'.
The statement has been terminated.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.ReportingServices.Library.RunningJobsDb.AddRunningJobs(Hashtable runningJobs)


View 10 Replies View Related

Cannot Insert Duplicate Key In Object 'dbo.RunningJobs'

Feb 22, 2007

We continue to recieve he following error on our RS 2005 SP1 Reporting Services installation:

Violation of PRIMARY KEY constraint 'PK_RunningJobs'. Cannot insert duplicate key in object 'dbo.RunningJobs'

This causes our server to become unresponsive and some reports to not render, Its becoming quite common. We reset IIS to correct it but is causes a service interuption. I know that it had been talked about before as something that may be fixed in SP2. But I do not see this referenced.


Does anybody know of any fix for this?



Thanks



Ron

View 1 Replies View Related

DTS Transfer Object Task - IDENTITY INSERT?

Nov 9, 1999

Good Afternoon,

Does anybody know if the DTS Transfer Object Task transfers tables with IDENTITY INSERT enabled? I'm copying objects, along with their data to another database, but I need to retain the values in my IDENTITY columns. I will do some manual checking but this is fairly tedious and error prone.

I've checked the Books Online but I couldn't find anything that answers my question.

Regards,

Robin

View 1 Replies View Related

SQL Server 2008 :: Cannot Insert Duplicate Key Row In Object

Jun 6, 2011

I have a SQL Server 2008 R2 on a windows 2008 server.After one failed backup, I started getting these errors:

Error: 2601, Severity: 14, State: 1.Cannot insert duplicate key row in object 'sys.syscommittab' with unique index 'si_xdes_id'.

Error: 3999, Severity: 17, State: 1.Failed to flush the commit table to disk in dbid 5 due to error 2601. Check the errorlog for more information.

From Microsoft, I found this:

A backup Operation On A SQL Server 2008 Database Fails If You Enable Change Tracking On This Database

[URL]

But this bug refers to SQL Server 2008. What should I do if in my case is a R2 version?

View 5 Replies View Related

SQL 2012 :: Backup Log Failed With Cannot Insert Duplicate Key In Object

Jun 17, 2014

One of my database transaction log backup jobs failed this morning, although the log backup was still taken, the job reported failure. The job has run successfully a number of times since. The job reported a primary key violation error on the msdb.dbo.backupmediaset table. The full error message was

Violation of PRIMARY KEY constraint 'PK__backupme__DAC69E4D599F1693'. Cannot insert duplicate key in object 'dbo.backupmediaset'. The duplicate key value is (401862).
Msg 3009, Level 16, State 1, Server myservername, Line 1

Could not insert a backup or restore history/detail record in the msdb database. This may indicate a problem with the msdb database. The backup/restore operation was still successful.

After investigating the backupset and backupmediaset tables in msdb I can see that value used for the failed insert was used previously for the last database log backup in the previous log backup run. The failure was reported for the first database log backup attempted. The SQL Log shows an entry for the log being backed up successfully.

I have checked the identify value in the backupmediaset table using DBCC CHECKIDENT and all looks OK.

DBCC CHECKIDENT ('backupmediaset',NORESEED)

Is there anything else I need to check?

View 6 Replies View Related

Cannot Insert Duplicate Key Row In Object 'MSmerge_genhistory' With Unique Index 'unc1MSmerge_genhistory'

Feb 28, 2007

I have 1 client who keeps running into the following error on the subscriber and merge agents >

€śCannot insert duplicate key row in object 'MSmerge_genhistory' with unique index 'unc1MSmerge_genhistory'.€?

Last time we got this error I ran a reindex on table MSmerge_genhistory on the publisher database, I then successfully generated a new snapshot and the subscribers started to synchronize again. This time around I keep getting the error even after I follow these steps (I also ran all the jobs to clean up replication). The last time I ran into this error I created a job to reindex msmerge_genhistory on a nightly bases in an effort to avoid this problem. Can somebody please provide me with a workaround and also the reason why this error occurs in the first place.

Thank you in advanced,
Pauly C

View 6 Replies View Related

Cannot Insert Duplicate Key Row In Object 'dbo.lastlogin' With Unique Index 'IX_lastlogin'.

Aug 22, 2007

Hi.

I have been recently redesigning my tables - creating FK
relationships from child tables to the PK userid in the Users table.
The specifics of what I did and why can be seen here:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1968856&SiteID=1

But, now I am getting the below error:

Cannot insert duplicate key row in object 'dbo.lastlogin' with unique index 'IX_lastlogin'.
The statement has been terminated.

Or, for that matter, SavedSearches or any other table where I need to
insert the same userid twice. I can see why I would want to avoid duplicates in the Users table. But, for lastlogin, savedsearches, and
a few of my other tables, the same user may account for multiple rows.

Any suggestions as to where I messed up and how to deal with this?

Thanks.


DBO.USERS






Code Snippet

CREATE TABLE [dbo].[users](
[userid] [int] IDENTITY(1,1) NOT NULL,
[lastname] [varchar](50) NULL,
[firstname] [varchar](50) NULL,
[email] [varchar](50) NOT NULL,
[alternateemail] [varchar](50) NULL,
[password] [varchar](50) NOT NULL,
[role] [varchar](10) NOT NULL,
[securityquestion] [varchar](50) NOT NULL,
[securityanswer] [varchar](50) NOT NULL,
[zipcode] [int] NOT NULL,
[birthmonth] [tinyint] NOT NULL,
[birthday] [tinyint] NOT NULL,
[birthyear] [int] NOT NULL,
[gender] [varchar](10) NULL,
[city] [varchar](50) NULL,
[state] [varchar](50) NULL,
[country] [varchar](50) NULL,
[registerdate] [datetime] NOT NULL,
[editdate] [datetime] NULL,
[confirmed] [bit] NULL CONSTRAINT [DF__Users__confirmed__4CC05EF3] DEFAULT ((0)),
CONSTRAINT [PK_users] PRIMARY KEY CLUSTERED
(
[userid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [IX_email] UNIQUE NONCLUSTERED
(
[email] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF


/****** Object: Table [dbo].[lastlogin] Script Date: 08/22/2007 14:16:16 ******/
SET ANSI_NULLS ON


DBO.SAVEDSEARCHES


CREATE TABLE [dbo].[savedsearches](
[savedsearchesid] [int] IDENTITY(1,1) NOT NULL,
[searchname] [varchar](50) NOT NULL,
[userid] [int] NOT NULL,
[date] [datetime] NULL,
[isdefault] [bit] NULL,
[gender] [char](10) NULL,
[startyear] [varchar](50) NULL,
[endyear] [varchar](50) NULL,
[country] [varchar](50) NULL,
[miles] [int] NULL,
[pictures] [varchar](50) NULL,
[postal] [int] NULL,
[sort] [tinyint] NULL,
[photostring] [varchar](50) NULL,
[orderby] [tinyint] NULL,
CONSTRAINT [PK_SavedSearches] PRIMARY KEY CLUSTERED
(
[userid] ASC,
[searchname] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[savedsearches] WITH NOCHECK ADD CONSTRAINT [FK_savedsearches_users] FOREIGN KEY([userid])
REFERENCES [dbo].[users] ([userid])
GO
ALTER TABLE [dbo].[savedsearches] CHECK CONSTRAINT [FK_savedsearches_users]
GO
SET QUOTED_IDENTIFIER ON
GO




The following insert statement returned the error in the subject because userid = 32 already exists in the Users table.

INSERT INTO lastlogin
VALUES (32, CONVERT(VARCHAR(26), GETDATE(), 109), 1, CONVERT(VARCHAR(26), GETDATE(), 109))

DBO.LASTLOGIN





Code Snippet


CREATE TABLE [dbo].[lastlogin](
[lastloginid] [int] IDENTITY(1,1) NOT NULL,
[userid] [int] NOT NULL,
[date] [datetime] NOT NULL,
[status] [bit] NOT NULL CONSTRAINT [DF_lastlogin_status] DEFAULT ((0)),
[activity] [datetime] NOT NULL CONSTRAINT [DF_lastlogin_activity] DEFAULT (getutcdate()),
[online] AS (case when [status]=(1) AND datediff(minute,[activity],getutcdate())<(30) then (1) else (0) end),
CONSTRAINT [PK_lastlogin] PRIMARY KEY CLUSTERED
(
[date] ASC,
[userid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[lastlogin] WITH NOCHECK ADD CONSTRAINT [FK_lastlogin_users] FOREIGN KEY([userid])
REFERENCES [dbo].[users] ([userid])
GO
ALTER TABLE [dbo].[lastlogin] CHECK CONSTRAINT [FK_lastlogin_users]

View 1 Replies View Related

Violation Of PRIMARY KEY Constraint 'PK_tblType'. Cannot Insert Duplicate Key In Object 'dbo.tblType'.

Oct 19, 2007

the point here that i have a small table with two fileds,
ID (guid) as primerykey
RAF(char)
and the table is empty when i add a new row i recieve this exception,
Violation of PRIMARY KEY constraint 'PK_tblType'. Cannot insert duplicate key in object 'dbo.tblType'.
i found no way to solve the problem.
thanks in advans
 

View 7 Replies View Related

SQL Server 2008 :: Violation Of Primary Key Constraints - Cannot Insert A Duplicate Key In Object

Sep 8, 2013

I have table variable in which I am inserting data from sql server database. I have made one of the columns called repaidID a primary key so that a clustered index will be created on the table variable. When I run the stored procedure used to insert the data. I have this error message; Violation of Primary key Constraint. Cannot insert duplicate primary key in object. The value that is causing this error is (128503).

I have queried the repaidid 128503 in the database to see if it is a duplicate but could not find any duplicate. The repaidID is a unique id normally use by my company and does not have duplicates.

View 9 Replies View Related

How Do I Call A Insert Stored Procedure From A Data Flow Destination Object?

Jun 26, 2007

I want to insert data calling a stored procedure and call this from a Data Flow destination object. Is it possible?



I understand that Ole Db Command transformation object can call stored procedure, but that will not rollback in the event of error in the middle.



I understand that Ole Db Destination object will rollback in middle of import, but I don't see how to do the insert by calling stored procedure. "Sql Command" option in Ole Db Destination object does not seem to present solution to the problem.



Am I missing something here or is Ssis / Microsoft demanding that Insert stored procedure not be used when using Data Flow destination object to insert data into target table?

View 8 Replies View Related

Contains Predicate

Jan 20, 2008

I run statement down,result is "go". why goes,gone,going is not in the result?
SELECT     ID, firstname, lastnameFROM         [contain-1]WHERE     CONTAINS(firstname, '  FORMSOF (INFLECTIONAL, go) ')
information table [contain-1]
ID        firstname
1           go
2          goes
3         gone
4         going
 

View 2 Replies View Related

Contains Predicate

Jan 20, 2008

what result this query?
SELECT  productname
FROM product
WHERE CONTAINS(productname,'spread NEAR boysenberry' )
explain word "NEAR".
Thanks,mohsen

View 1 Replies View Related

Contains Predicate

Jan 26, 2008

I run query down.result is null.
 SELECT ID, firstname, lastname
FROM [contain-1]
 WHERE CONTAINS(firstname, 'pooya NEAR yaser')
 
 table [contains-1]  information:
ID         firstname
1            pooya
2            mehdi
3           peter
4          yaser
 
why result is null? 
thanks,mohsen

View 1 Replies View Related

Contains Predicate

Jan 30, 2008

I run query down.result is null.
 SELECT ID, firstname, lastname
FROM [contain-1]
 WHERE CONTAINS(firstname, 'pooya NEAR yaser')
 
 table [contains-1]  information:
ID         firstname
1            pooya
2            mehdi
3           peter
4          yaser
5        pooyaandyaser
why result is null? 
thanks,mohsen

View 2 Replies View Related

Contains Predicate

Feb 1, 2008

I run query down.result is null.
 Why is result null?
SELECT     ID, firstnameFROM         [contain-1]WHERE     CONTAINS(firstname, 'yaser NEAR pooya')
table information:
ID             firstname
1                ali
2              peter
3               yaser
4             yaserapooya
5            mehdi
 
Thanks,mohsen
 

View 1 Replies View Related

Using Like Predicate

Jul 20, 2005

Hi,i want to search record in a table where a varchar column is equal toa word or this word with the letter 's' or this word with the letter'e'.Today, i've this query :select * From Table Where Column = 'Word' or Column like 'Word[es]'I want to remove the 'or' of this query to have only one condition.Does someone know a solution to my problem.Excuse my poor english language.I hope you understand my problem and thks for solution.

View 2 Replies View Related

Cannot Insert Duplicate Key Row In Object 'dbo.blabla..' With Unique Index 'Idx_blablabl'. The Statement Has Been Terminated. At

Jan 16, 2007

We are developing a project that is expected to hold TB of data and the back end used is SQL Server 2005.

I have the following problem

I have applied Nonclustered index over a column on a table.

Designed a SP for insertion which caters for updation incase the criteria based on the input is met.

The logic goes like this

Incase there exists a row containing the value of the column that is indexed for uniqueness, there should be updation. If not there should be a new row created.



However often there is an error message that is placed above. This happens only on some of the SPs and only on rare occasions.

Can any body tell me if there is any problem with the SQL Server 2005







Thanks in advance

R Suresh, SQLDBA







View 8 Replies View Related

Search Using The CONTAINS Predicate

Jun 27, 2006

Hi everybody,
I have a problem using the CONTAINS predicate. I use the contains
predicate in a web page that students utilize to look for dissertations
stored in a database (MS 2000) of the library. The search  is one
big textbox where students can perform any type of reaserch. For
instance, they can insert the author, the title or few keywords of a
dissertation. After they have clicked on the button Submit, the words
that they have inserted are filtered and combined  (with AND) in
one string:
Example: miami, education --> 'Miami AND Education'

An example of the query that I need to perfrom is the Query Number 1:

select docnumber,Title


FROM [Log].[dbo].[DocTable1]


where contains(SearchColumn,'miami AND education') order by docnumber

SearchColumn is a field (varchar) that is the concatenation of various
fields such as Location, Title, Author, etc... that are contained in
the same table (See below for the description of the Table DocTable1).

 I'm currently testing the search and I have figured out that the query described above does not work.
For example, the query should produce the same resultsof the following one, but it does not:

select docnumber
FROM [Log].[dbo].[DocTable1]
where contains(Location,'miami') AND
contains(Keywords,'education') order by docnumber

I need to implement the first query, but i can not understand why it
does not produce the same results of the second one. Any Ideas?

Thanks,
Christian

--------------------------------------------------------------
CREATE TABLE [DocTable1] (
    [DocNumber] [int] NOT NULL ,
    [LastName] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [FirstName] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [Program] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [Paper] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [Location] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [ANNO] [int] NULL ,
    [Title] [varchar] (350) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [TitleSort] [varchar] (350) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [Keywords] [varchar] (350) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [FT] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [URL] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [SearchColumn] [varchar] (900) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    CONSTRAINT [PK_DocTable1] PRIMARY KEY  CLUSTERED
    (
        [DocNumber]
    )  ON [PRIMARY] ,
    CONSTRAINT [Title_Author_DocTable1] UNIQUE  NONCLUSTERED
    (
        [Title],
        [LastName],
        [FirstName]
    )  ON [PRIMARY] ,
    CONSTRAINT [FT-Constraint] CHECK  NOT FOR REPLICATION ([FT] = 'Y' or [FT] = 'N')
) ON [PRIMARY]
GO

View 5 Replies View Related

LIKE Predicate Using SQL Parameter

Jan 4, 2007

I am having problems with the following SQL statement.  It works how I want it to work if I use = @SearchQuery but when I try to switch to LIKE I run into problems. I tried it the way it is shown below and I also tried LIKE '%'@SearchQuery'%' with no luck.  Does this have something to do with the pattern to match being a parameter? How would I go about doing this correctly.   
"SELECT server_info.*, network_adapter.* FROM server_info LEFT JOIN network_adapter " +                "ON server_info.server_id = network_adapter.server_id WHERE " + DropDownList1.SelectedValue.ToString() + " LIKE '%@SearchQuery%'"
Thanks
 

View 2 Replies View Related

Using A Variable In An IN Predicate

Oct 3, 2007

Anybody know how to do this?
"Select something from some table where id in (@IDlist)"
where @IDlist is a comma-separated list of values (or something top that effect)

View 1 Replies View Related

Predicate Locking

Jul 23, 2005

HiI am having a debate with one of the Postgres developers (Tom Lane)according to him ms-sql does not implement predicatelocking(SERIALIZABLE).Where predicate locking is defined as (from the postgres help):"12.2.2.1. Serializable Isolation versus True Serializability"It states: "To guarantee true mathematical serializability, it isnecessary for a database system to enforce predicate locking, whichmeans that a transaction cannot insert or modify a row that would havematched the WHERE condition of a query in another concurrenttransaction"Now I put it to him that that is exactly what SERIALIZABLE does isMS-SQL.But his response was "Only for WHERE conditions that can be expressedas a simple range constraint."Now is he correct i.e SERIALIZABLE works "Only for WHERE conditionsthat can be expressed as a simple range constraint." ?Regards,Daniel RothMCSD.NET

View 8 Replies View Related

NO JOIN PREDICATE

Apr 21, 2008

am encountering the NO JOIN PREDICATE warning in a query plan for a particualr SQL statement. In poking around, I've come across psotings that mention the CU 4 for SQL Server 2005. The update applies to a KB article that addresses complex queries with an outer join.

But in my case, it's not an outer join causeing the problem - they are all left joins. Here is the piece of SQL that is running extremely slowly:




Code Snippet
UPDATE @TESTTABLE
SET [@TESTTABLE].SignInCancelledNoEMR =
(SELECT q.cnt FROM
(SELECT COUNT(*) AS cnt,cl.Clinic_id AS ClinicIDq,cl.CLINIC_REG_ID AS MarketIDq
FROM dbo.tblactivity AS t
LEFT JOIN [ERIIProduction].dbo.computer c on t.machineid = c.comp_windowsname
LEFT JOIN [ERIIProduction].dbo.clinic cl on cl.clinic_id = c.comp_clinic_id
LEFT JOIN [ERIIProduction].dbo.Region r ON cl.CLINIC_REG_ID = r.REG_ID
WHERE t.status = '1'
AND cast(checkindate as datetime) >= @startDate
AND cast(checkindate as datetime) < DATEADD(d, 1, @endDate)
AND cl.clinic_reg_id IN (SELECT Item FROM dbo.Split(@regionIDList,','))
AND NOT EXISTS (SELECT 1 FROM [ERIIProduction].dbo.VisitPatient vp WHERE (t.activityid = vp.VSPAT_GalvanonActivityID)) --AND (t.memberid = vp.VSPAT_GalvanonMemberID))
GROUP BY cl.Clinic_id,cl.CLINIC_REG_ID) AS q
WHERE q.ClinicIDq = ClinicID AND q.MarketIDq = MarketID)






Before I apply the CU and enable the trace flags, I'd like to know if there is something else I can do within the query itself to make it run faster. I've tried the OPTION(FORCE ORDER ) hint, but that doesn't have any effect on the queery run time.
And as a whole, the query cost relative to the entire batch jumped from 75% to 96%.

Granted the execution time of the entire batch dropped from 9 minutes to 1 minute, this query should not even take that long.

Thanks for any input...!

View 6 Replies View Related

TSQL - Using Contains Predicate

Aug 16, 2007

Hi guys,
I need to change some characters when reading the values of a certain columns, I am trying to use something like the code below, but the following error:
"Cannot use a CONTAINS or FREETEXT predicate on table 'JURNALTRANS' because it is not full-text indexed."




Code Snippet

CASE
WHEN Contains (JurnalTrans.DESCRIPTION, 'A') THEN Replace(JurnalTrans.DESCRIPTION,'A','A1')
WHEN Contains (JurnalTrans.DESCRIPTION, 'B') THEN Replace(JurnalTrans.DESCRIPTION,'B','B2')
ELSE JurnalTrans.DESCRIPTION
END AS 'Cost Description',




I am also trying something like this



Code SnippetSELECT DESCRIPTION AS 'X' FROM JURNALTRANS WHERE CONTAINS(DESCRIPTION, 'Y')

but getting the same error
"Cannot use a CONTAINS or FREETEXT predicate on table 'JURNALTRANS' because it is not full-text indexed."

Any help will be appreciated,
Thanks in advance,
Aldo.

View 4 Replies View Related

BETWEEN Predicate With Passed Parameters

Apr 14, 2004

I have a report in SQL that passes parameters at runtime entered by the user for two date ranges (beginning and ending). I'm trying to write a formula that will print a specific field *only if* the specified date range entered by the user is BETWEEN a specific value (like 200401). This is kind of reverse of a normal WHERE, BETWEEN clause.

I tried a standard BETWEEN predicate in my WHERE clause like:
IF '200401' BETWEEN ?BegPer and ?EndPer then salesanal.ptdbud01 else 0

But, it's returning an error that my Then statement is missing. I can't use a normal statement like 'IF ?BegPer >= '200401' and ?EndPer <= '200401', then.....' because users could enter a RANGE of periods, so it would be difficult to code all of the possible combinations this way. I'm actually doing this in Crystal, but if someone can give me a standard MSSQL example, I can translate that over to Crystal.

Thanks in advance,
Michelle

View 4 Replies View Related

No Predicate Join Work Around

Oct 8, 2015

I have two tables. Table A has 2162 rows and table B has 101 rows. There isn't any join keys that I can join on these two tables. But I need everything from table B and only one column (Col1) from table A. It will result in a cross join and retruns 218362 (2162 * 101) rows, which is correct. But this takes about 30 seconds to complete. Any workaround to accomplish this? Optimizer shows no predicate joins on the Nested Loop and to me it is correct.

Here is what I have so far.

SELECT B.*, A.col1
FROM TableB B
LEFT JOIN TABLE A A
ON 1 = 1

View 9 Replies View Related

Contains Predicate And Double Quotes

Jul 20, 2005

I have been searching for an escape character or a way of escapingdouble quotes that are actually in a string that I am using in thecontains predicate.Here is an exampleselect *from tablewhere contains(field, '"he said "what is wrong", that is what hesaid"')I need the double quotes in the string because they are part of thetext. Of course, Fulltext search raises the errorServer: Msg 7631, Level 15, State 1, Line 1Syntax error occurred near 'what is wrong", that is what he said'.Expected ''''' in search condition '"he said "what is wrong", that iswhat he said"'.If I remove the double quotes, the search does not return the properresults.Thanks in advance for the helpBill

View 2 Replies View Related

Using CASE Statement In CONTAINS Predicate

Oct 22, 2007

Hi,

I am using Microsoft FullText search feature in my database for Searching
strings.

I want to use CASE statement in CONTAINS.
DECLARE @allowSearchALL int

SELECT [ID] ,[Source] ,[Description],name

FROM [Search]

WHERE CONTAINS( Source , '"mail"')

i know we can use CASE in WHERE clause...but dono how to use CONTAINS with
CASE.

My Requirement is

if @allowSearchALL is 1 then get all records otherwise use specified
hardcoded text "mail"

I have to use CONTAINS.

I would like use some thing like this,

SELECT [ID] ,[Source] ,[Description],name

FROM [Search]

WHERE Source = CASE WHEN @allowSearchALL = 1 THEN Source ELSE 'mail' END

This way i can map column name to same column name if @allowSearchALL = 1 .
I do not want to use multiple IF blocks like if ( )
begin

end
else if( )
begin

end


How this can be done in CONTAINS ? like WHERE CONTAINS(source, CASE ....ELSE
...END)

Please give me solution for this.

Thanks in advance

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved