Why does this update query not work? - sql

I am pretty new with SQL Server and DBMS and I have some problem with the following query that upade a single record of a table named: MaliciousCodeAlertDocument
This is my query:
UPDATE MaliciousCodeAlertDocument
SET Discovered = GetDate(),
LastUpdated = GetDate(),
SourceId = "UP",
MalCodeID = 1,
Title = "UPDATED",
Origin = "UP",
Type = "UP",
Feature = "UP",
Risk = "UP",
Severity = 1,
OverallImpact = 1,
ContagionPotential = 1,
Wild = "UP",
AlertStatusID = 1,
AttributeType = 1,
DetailLevel = 1 ,
Language = 1 ,
Summary = "UP" ,
Symptom = "UP" ,
TechnicalDescription = "UP" ,
MitigatingStrategy = "UP" ,
Disinfection = "UP" ,
URL = "UP"
WHERE Id = 11316
When I try to execute it I obtain the following error message:
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UP'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UPDATED'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UP'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UP'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UP'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UP'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UP'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UP'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UP'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UP'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UP'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UP'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UP'.
What is the problem? How can I fix it?
Tnx

Using double-quotes makes SQL Server think that the value within the quotes is a column, but it looks like you're trying to update it to a text value. If you use single quotes instead, SQL will recognize that you want to insert that value into your field, and should load it correctly.
EDIT: Sorry, didn't see that #scragar already posted this solution. Anyone know if I'm supposed to delete my answer because of this?

Related

SQL Unpivot Conflicting columns name error

I have 'book value' and 'Asset type' columns with set asset type values - 'NCD','GSEC' and 'EQU' .
I want to use unpivot and convert them from rows to cols using UNPIVOT but i am getting errors as follows.
Msg 207, Level 16, State 1, Line 267
Invalid column name 'GSEC'.
Msg 207, Level 16, State 1, Line 267
Invalid column name 'EQU'.
Msg 265, Level 16, State 1, Line 267
The column name "Book Value" specified in the UNPIVOT operator conflicts with the existing column name in the UNPIVOT argument.
Msg 265, Level 16, State 1, Line 267
The column name "Asset Type" specified in the UNPIVOT operator conflicts with the existing column name in the UNPIVOT argument.
Msg 8156, Level 16, State 1, Line 267
The column 'Book Value' was specified multiple times for 'UNPVT'.
This is the code snippet i am using
Select [Book Value],[Asset Type]
FROM [DBname].[dbo].[Final Base Data-4]
UNPIVOT([Book Value] For [Asset Type]
in ([NCD],[GSEC],[EQU])) AS UNPVT;

I am trying to copy from one column to another in same table but getting msg 50000 and error 3609 as well

UPDATE poitem_mst
SET Uf_TYRI_poitem_req_ship_date=promise_date
Should be simple, but I get these errors:
Msg 50000, Level 16, State 1, Procedure RaiseErrorSp, Line 121 [Batch Start Line 0]
Purchase Order that has [PO: P000010685] does not exist.
Msg 3609, Level 16, State 1, Line 1
The transaction ended in the trigger. The batch has been aborted.
The PO number changes every time I run that query.

Stored procedure for inserting the new records in the table from data table

I am getting an error while creating the below stored-procedure which would insert the new records in the table from the data table
CREATE PROCEDURE [dbo].[SP_Cde_SecureList_Upsert]
#SecureList SecureList READONLY,
#ListType varchar(20)
AS
BEGIN
IF(#ListType='FETCHDETAILS')
SELECT * FROM TBL_TICKETING_ALTERNATE_CREDIT_CARD_LIST
ELSE
BEGIN
INSERT INTO TBL_TICKETING_ALTERNATE_CREDIT_CARD_LIST([CardRefID], [KEY], [MIS_Field1], [MIS_Field2], [ValidatingCarrier]
, [OtherCarriers], [Card Vendor], [Card], [Expiration], [Precedence], [AlertEmail], [maxTktAmt], [IRP_remark])
SELECT [CardRefID], [KEY], [MIS_Field1], [MIS_Field2], [ValidatingCarrier]
, [OtherCarriers], [Card Vendor], [Card], [Expiration], [Precedence], [AlertEmail], [maxTktAmt], [IRP_remark] FROM #SecureList;
END
END
GO
Error:
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 12 [Batch Start Line 60]
Invalid column name 'CardRefID'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 12 [Batch Start Line 60]
Invalid column name 'MIS_Field1'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 12 [Batch Start Line 60]
Invalid column name 'MIS_Field2'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 12 [Batch Start Line 60]
Invalid column name 'ValidatingCarrier'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'OtherCarriers'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'Card Vendor'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'Card'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'Expiration'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'Precedence'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'AlertEmail'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'maxTktAmt'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'IRP_remark'.
Completion time
which is strange since the column names are correct
Below is the screenshot of my SP and header/columns of the table wherein I am trying to insert the data from the data table
SP and table column details screenshot
If I do select * from the data table
CREATE PROCEDURE [dbo].[SP_Cde_SecureList_Upsert]
#SecureList SecureList READONLY,
#ListType varchar(20)
AS
BEGIN
IF(#ListType='FETCHDETAILS')
SELECT * FROM [dbo].[TBL_TICKETING_ALTERNATE_CREDIT_CARD_LIST]
ELSE
BEGIN
INSERT INTO [dbo].[TBL_TICKETING_ALTERNATE_CREDIT_CARD_LIST](CardRefID, [KEY], MIS_Field1, MIS_Field2, ValidatingCarrier
, OtherCarriers, [Card Vendor], Card, Expiration, Precedence, AlertEmail, maxTktAmt, IRP_remark)
SELECT * FROM #SecureList;
END
END
GO
I am getting an error as
Msg 120, Level 15, State 1, Procedure SP_Cde_SecureList_Upsert, Line 10 [Batch Start Line 60]
The select list for the INSERT statement contains fewer items than the insert list. The number of SELECT values must match the number of INSERT columns.
This doesn't have anything to do with C# so you should remove the tag from your question. Could you provide the error message?

How do I create an eventlog event upon a SQL connectivity issue? Here's my concrete example:

I need to connect to an external database and the connectivity may sometimes fail. However, I am seeing that if the SELECT statement below fails, the IF statement after that does not execute at all:
SELECT COUNT(*) FROM [DB].[View]
IF ##ERROR <> 0
BEGIN
EXEC xp_logevent 63000, 'Issue!', error
END
Here's the error message:
Msg 8180, Level 16, State 1, Line 32
Statement(s) could not be prepared.
Msg 4413, Level 16, State 1, Line 32
Could not use view or function 'DB.view' because of binding errors.
Msg 208, Level 16, State 1, Procedure Servers2Switchs, Line 60
Invalid object name xxx.

The multi-part identifier could not be bound using a linked server with ODBC connection to a DB2

when I run this simple query
select [B00BF4CR].[IWSE4S8].[SCTRN].[STCOMP],
[EPAK].[B00BF4CR].[IWSE4S8].[SCTRN].[STDATE],
[EPAK].[B00BF4CR].[IWSE4S8].[SCTRN].[STUNM],
[EPAK].[B00BF4CR].[IWSE4S8].[SCTRN].[STQTY]
FROM [EPAK].[B00BF4CR].[IWSE4S8].[SCTRN]
WHERE [EPAK].[B00BF4CR].[IWSE4S8].[SCTRN].[STCOMP]='51'
AND [EPAK].[B00BF4CR].[IWSE4S8].[SCTRN].[STDATE] = 20140211
AND [EPAK].[B00BF4CR].[IWSE4S8].[SCTRN].[STVOID] = 'N'
ORDER BY [EPAK].[B00BF4CR].[IWSE4S8].[SCTRN].[STTCKT]
in my sql I got the below errors
Msg 4104, Level 16, State 1, Line 3
The multi-part identifier "EPAK.B00BF4CR.IWSE4S8.SCTRN.STCOMP" could not be bound.
Msg 4104, Level 16, State 1, Line 4
The multi-part identifier "EPAK.B00BF4CR.IWSE4S8.SCTRN.STDATE" could not be bound.
Msg 4104, Level 16, State 1, Line 4
The multi-part identifier "EPAK.B00BF4CR.IWSE4S8.SCTRN.STVOID" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "B00BF4CR.IWSE4S8.SCTRN.STCOMP" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "EPAK.B00BF4CR.IWSE4S8.SCTRN.STDATE" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "EPAK.B00BF4CR.IWSE4S8.SCTRN.STUNM" could not be bound.
Msg 4104, Level 16, State 1, Line 2
The multi-part identifier "EPAK.B00BF4CR.IWSE4S8.SCTRN.STQTY" could not be bound.
Msg 4104, Level 16, State 1, Line 5
The multi-part identifier "EPAK.B00BF4CR.IWSE4S8.SCTRN.STTCKT" could not be bound.
when I do double clic on the 1st one it highlight this section
FROM [EPAK].[B00BF4CR].[IWSE4S8].[SCTRN]
WHERE [EPAK].[B00BF4CR].[IWSE4S8].[SCTRN].[STCOMP]='51' AND
the 2nd and the 3rd ones
[EPAK].[B00BF4CR].[IWSE4S8].[SCTRN].[STDATE] = 20140211
AND [EPAK].[B00BF4CR].[IWSE4S8].[SCTRN].[STVOID] = 'N' ORDER BY
4, 5 and 6
select [B00BF4CR].[IWSE4S8].[SCTRN].[STCOMP],
[EPAK].[B00BF4CR].[IWSE4S8].[SCTRN].[STDATE],
[EPAK].[B00BF4CR].[IWSE4S8].[SCTRN].[STUNM],
7
[EPAK].[B00BF4CR].[IWSE4S8].[SCTRN].[STQTY]
8
[EPAK].[B00BF4CR].[IWSE4S8].[SCTRN].[STTCKT]
At most, you can have a four part notation. Your query is invalidating that rule for the column names. A table alias comes in handy to avoid this issue.
[LINKEDSERVER].[DATABASE].[OWNER].[OBJECT]
Here is a rewrite of the query.
-- Use a table alias
SELECT
S.[STCOMP],
S.[STDATE],
S.[STUNM],
S.[STQTY]
FROM
[EPAK].[B00BF4CR].[IWSE4S8].[SCTRN] AS S
WHERE
S.[STCOMP]='51' AND
S.[STDATE] = 20140211 AND
S.[STVOID] = 'N'
ORDER BY
S.[STTCKT]
There are some issues with updates and deletes using Distributed Query Processing (DQP) through DB2OLEDB.
See article below for warning about this as well as examples of pass thru query vs linked server.
http://support.microsoft.com/kb/222937