Subquery returned more than 1 value in insert statement - sql-server-2008

I need solution to fix this error Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
I don't have subquery in my insert statement but still I am getting this error.
Code:
INSERT INTO enquiries_dtls(confdate,confname,region,enquiry,attendedby,dctname,
hospital,contactno,email,addr)
VALUES('10/04/2013',
'APAO',
'Delhi',
'test',
'test',
'test',
'test',
'123214',
'abc#abc.com',
'test')
DDL:
CREATE TABLE [dbo].[enquiries_dtls]
(
[sno] [int] IDENTITY(1,1) NOT NULL,
[Timestamp] [timestamp] NULL,
[confdate] [date] NULL,
[confname] [varchar](max) NULL,
[region] [varchar](50) NULL,
[enquiry] [varchar](max) NULL,
[attendedby] [varchar](50) NULL,
[dctname] [varchar](50) NULL,
[hospital] [varchar](50) NULL,
[contactno] [int] NULL,
[email] [varchar](50) NULL,
[addr] [varchar](max) NULL,
[stsupdate] [varchar](max) NULL,
[dtupdate] [date] NULL,
[closingdate] [date] NULL,
[clsedby] [varchar](50) NULL,
[revenue] [varchar](50) NULL,
[apprstatus] [varchar](50) NULL,
[clsed] [varchar](50) NULL,
[enqId] [varchar](50) NULL
);

Related

How to update column in SQL Server 2008

I'm new to SQL Server so any help with this would be greatly appreciated. I can not find the error while update the existing column with autogenerated record
Here is my table structure:-
CREATE TABLE [dbo].[EmployeeRegistration]
(
[ID] [int] NULL,
[Sr_no] [int] IDENTITY(1,1) NOT NULL,
[Branch_Code] [varchar](200) NULL,
[City] [varchar](200) NULL,
[Employee_Name] [varchar](200) NULL,
[Designation] [varchar](200) NULL,
[Department] [varchar](200) NULL,
[Date_of_Joining] [varchar](200) NULL,
[Reporting_To] [varchar](200) NULL,
[Staff_Code] [varchar](50) NULL,
[Reporting_To_1] [varchar](200) NULL,
[Staff_Code_1] [varchar](50) NULL,
[Emp_Staff_Code] AS ('T'+right('0000'+CONVERT([varchar](8),[Sr_no],(0)),(8))),
[Password] [varchar](50) NULL,
[confirmPassword] [varchar](50) NULL,
[EMAIL_id] [varchar](50) NULL,
[IsActive] [varchar](200) NULL,
[Created_By] [varchar](200) NULL,
[Created_On] [date] NOT NULL,
[Modified_By] [varchar](200) NULL,
[Modified_Date] [date] NOT NULL
)
I want to update Password column with below query:-
use AxpressDB
alter table EmployeeRegistration
alter column Password AS ('XP'+right('0123'+CONVERT([varchar](50),[Sr_no],(0)),(8)))
The syntax for the column altering :
ALTER TABLE tablename
ALTER COLUMN columnname columndatatype(size)
and the example :
ALTER TABLE dbo.doc_exy
ALTER COLUMN column_a DECIMAL (5, 2) ;
Try these manner
You cannot alter an existing column and make it as computed column, you need to drop and recreate
alter table EmployeeRegistration
drop column Password
alter table EmployeeRegistration
add Password AS ('XP'+right('0123'+CONVERT([varchar](50),[Sr_no],(0)),(8)))

Convert MSSQL to mysql table

Can I know the easiest way to convert the Microsoft sql query to MYSQL.
sample query of Microsoft sql query:
CREATE TABLE [dbo].[T_NEWBIZ](
[newbID] [int] IDENTITY(1,1) NOT NULL,
[planID] [int] NULL,
[applID] [int] NULL,
[taxqID] [int] NULL,
[doptID] [int] NULL,
[stcoID] [int] NULL,
[crsnID] [int] NULL,
[newbEPBR] [bit] NULL,
[newbPolicyNo] [varchar](50) NULL,
[newbEffectiveDate] [varchar](20) NULL,
[newbIssueDate] [varchar](20) NULL,
[newbDistributorOrderNumber] [varchar](30) NULL,
[newbJointAnnuitantNA] [bit] NULL,
[newbOwnerIsAnnuitant] [bit] NULL,
[newbDeliveryEMail] [varchar](100) NULL,
[newbDeliveryConsent] [bit] NULL,
[newbAnnuityOptionSpecialRequest] [varchar](500) NULL,
[newbCSRID] [varchar](20) NULL,
[newbBrokerID] [varchar](10) NULL,
[newbUGMA] [bit] NULL,
[newbUTMA] [bit] NULL,
[newbRecapAvailable] [bit] NULL,
[newbOriginatorCode] [varchar](8) NULL,
[newbFileNetStatus] [char](1) NULL,
[newbJointOwnerNA] [bit] NULL,
[newbNameChange] [bit] NULL,
[newbDateCompleted] [datetime] NULL,
[newbSuitabilityStatus] [varchar](25) NULL,
[newbClientNumber] [varchar](15) NULL,
[newbCheckPayable] [bit] NULL,
[newbMSANumber] [varchar](11) NULL,
[newbPrincipalReviewer] [varchar](10) NULL,
[newbCreationDate] [datetime] NULL,
[newbAnyExistingPolicies] [varchar](1) NULL,
[newbCreatedBy] [varchar](50) NULL,
[newbReplaceExistingPolicy] [varchar](1) NULL,
[newbFormsVerified] [bit] NULL,
[newbTransfer1035] [varchar](1) NULL,
[newbFormsComment] [varchar](500) NULL,
[newbADRequired] [bit] NULL,
[newbAssignedCSRID] [varchar](10) NULL,
[newbBackupWithholding] [varchar](1) NULL,
[newbSuitabilityApprovedDate] [datetime] NULL,
[newbExchangeInternal] [bit] NULL,
[newbAnnuityDate] [varchar](20) NULL,
[newbAnnuityDateOverride] [bit] NULL,
[newbAnnuityOption] [varchar](1) NULL,
[newbSpecialRequest] [varchar](500) NULL,
[newbSpecialRequestNA] [bit] NULL,
[newbFraudAccepted] [bit] NULL,
[newbHireDate] [varchar](20) NULL,
[newbAppless] [bit] NULL,
[newbMailToClient] [bit] NULL,
[newbPGR] [bit] NULL,
[newbDataLock] [varchar](8) NULL,
[amlsCode] [varchar](1) NULL,
[newbFEPlanCodeIndicator] [bit] NULL,
[newbFEPlanCodeDate] [varchar](10) NULL,
[newbBestPlusClientID] [varchar](10) NULL,
[newbDetachedOfficeIndicator] [char](1) NULL,
[newbDetachedOfficeCode] [varchar](5) NULL,
[newbPreviousWFM] [bit] NULL,
[newbARDForm1] [bit] NULL,
[newbARDForm2] [bit] NULL,
[newbARDForm3] [bit] NULL,
[newbARDForm4] [bit] NULL,
[newbARDForm5] [bit] NULL,
[newbPSO] [bit] NULL,
CONSTRAINT [PKC_NewBiz_cnewbID] PRIMARY KEY NONCLUSTERED
(
[newbID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 95) ON [PRIMARY]
) ON [PRIMARY]
You can use mysql workbench to do so, I converted mssql database to MySQL database.
Here is the link to tutorial, it has all the details along with screenshots.

SQL INSERT statement conflicted with the CHECK constraint

I am getting this error
InsertRecord(InsertRow): HResult of -2147217873 (80040e2f)
Error Source: Microsoft OLE DB Provider for SQL Server Error
Description : The INSERT statement conflicted with the CHECK constraint CK_ContactName. The conflict occurred in database EPIC.7.5_GR_SM_ETLTRAINING; table dbo.ContactName.
The Statements
CREATE TABLE [dbo].[ContactName](
[UniqContactName] [dbo].[DM_UNIQID] IDENTITY(65536,1) NOT NULL,
[UniqFixedContactName] [dbo].[DM_UNIQID] NOT NULL,
[UniqEntity] [dbo].[DM_UNIQID] NOT NULL,
[LkPrefix] [dbo].[DM_PREFIX] NOT NULL,
[FullName] [dbo].[DM_NAME] NOT NULL,
[FirstName] [varchar](30) NOT NULL,
[MiddleName] [varchar](16) NOT NULL,
[LastName] [varchar](30) NOT NULL,
[LkSuffix] [dbo].[DM_SUFFIX] NOT NULL,
[DescriptionOf] [dbo].[DM_DESC_050] NOT NULL,
[Title] [dbo].[DM_TITLE] NOT NULL,
[Department] [dbo].[DM_DEPARTMENT] NOT NULL,
[UniqContactAddressMain] [dbo].[DM_UNIQID] NOT NULL,
[UniqContactAddressEmployer] [dbo].[DM_UNIQID] NOT NULL,
[UniqContactNumberMain] [dbo].[DM_UNIQID] NOT NULL,
[UniqContactNumberEmailMain] [dbo].[DM_UNIQID] NOT NULL,
[ContactMethodCode] [char](1) NOT NULL,
[InformalHeading] [varchar](50) NOT NULL,
[FormalHeading] [varchar](50) NOT NULL,
[BirthDate] [dbo].[DM_DATE] NULL,
[GenderCode] [char](1) NOT NULL,
[SSN] [char](9) NOT NULL,
[MaritalStatusCode] [char](1) NOT NULL,
[RelationToInsuredCode] [char](2) NOT NULL,
[LkLanguage] [dbo].[DM_LANGUAGE] NOT NULL,
[Comments] [dbo].[DM_COMMENT] NOT NULL,
[BillingDeliveryCode] [char](1) NOT NULL,
[ServicingDeliveryCode] [char](1) NOT NULL,
[MarketingDeliveryCode] [char](1) NOT NULL,
[CategoryCode] [char](1) NOT NULL,
[EmployerName] [dbo].[DM_NAME] NOT NULL,
[LkOccupation] [dbo].[DM_OCCUPATION] NOT NULL,
[HiredDate] [dbo].[DM_DATE] NULL,
[YearsEmployed] [smallint] NULL,
[YearsPriorEmployer] [smallint] NULL,
[FEIN] [char](9) NOT NULL,
[DUNSNumber] [char](9) NOT NULL,
[CdNAICSCode] [char](6) NOT NULL,
[CdSICCode] [char](8) NOT NULL,
[BusinessTypeCode] [char](2) NOT NULL,
[BusinessTypeOtherDesc] [varchar](50) NOT NULL,
[NumberEmployees] [smallint] NULL,
[NumberMembersManagers] [int] NULL,
[BusinessStartedDate] [datetime] NULL,
[NatureOfBusinessCode] [char](2) NOT NULL,
[NatureOfBusinessOtherDesc] [varchar](50) NOT NULL,
[CreditBureauNameCode] [char](5) NOT NULL,
[CreditBureauNameOtherDesc] [varchar](50) NOT NULL,
[CreditBureauIDNumber] [varchar](30) NOT NULL,
[DriverLicenseNumber] [varchar](25) NOT NULL,
[LicensedState] [char](4) NOT NULL,
[LicensedDate] [datetime] NULL,
[LicensedMADate] [dbo].[DM_DATE] NULL,
[DriverTypeCode] [char](1) NOT NULL,
[GoodStudentCode] [char](1) NOT NULL,
[DriverTrainingCode] [char](1) NOT NULL,
[AccidentPreventionCourseDate] [dbo].[DM_DATE] NULL,
[CommercialExperienceBeganDate] [dbo].[DM_DATE] NULL,
[MatchClientNameOf] [smallint] NOT NULL,
[InsertedByCode] [dbo].[DM_INSERTUPDATEBYCODE] NOT NULL,
[InsertedDate] [dbo].[DM_DATETIME] NOT NULL,
[UpdatedByCode] [dbo].[DM_INSERTUPDATEBYCODE] NOT NULL,
[UpdatedDate] [dbo].[DM_DATETIME] NULL,
[Flags] [dbo].[DM_FLAGS] NOT NULL,
[ts] [datetime] NOT NULL,
[SIN] [char](9) NOT NULL,
[BusinessNumber] [varchar](30) NOT NULL,
[BusinessIDNumber] [varchar](30) NOT NULL,
[IBCCode] [char](6) NOT NULL,
CONSTRAINT [PK_ContactName] PRIMARY KEY NONCLUSTERED ALTER TABLE [dbo].[ContactName]
WITH CHECK ADD CONSTRAINT [CK_ContactName]
CHECK ((
[UniqContactName]=(-1)
AND [UniqEntity]=(-1)
OR [UniqContactName]>(-1)
AND [UniqEntity]>(-1)
))
GO
I have checked contactName db and all the rows from uniqueContactName all have a value above 65000, then for UniqEntity they all are above 65000 as well.
Does anyone have an idea why this would fail?

SQL Error : "Incorrect syntax near"

I have a database that is connected to SQL Server 2008, I am getting an error when printing database : Printing aborted! Error 37000 (Microsoft OLE DB Provider for ODBC Drivers) - [Microsoft] [ODBC SQL Server Driver] [SQL Server] [Incorrect syntax near 'TEMP_TAB_SHEET_U17'.
Details script as below :
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [data].[TEMP_TAB_SHEET_U17](
[TAL] [varchar](30) NULL,
[Phase] [smallint] NOT NULL,
[SHT] [varchar](30) NULL,
[PreferedSYS] [varchar](30) NULL,
[sysdesc] [varchar](100) NULL,
[EquipmentNumber] [varchar](30) NULL,
[TaskNumber] [varchar](30) NULL,
[TaskId] [int] NULL,
[OTdescription] [varchar](50) NULL,
[OTremark] [varchar](50) NULL,
[Estimated_Man_Hours] [float] NULL,
[EquipmentId] [int] NULL,
[EquipmentDescription] [varchar](50) NULL,
[TAA_ID] [int] NULL,
[UserGroup] [varchar](30) NULL,
[MODULE] [varchar](30) NULL,
[ModuleDesc] [varchar](50) NULL,
[SHTTitle1] [varchar](50) NULL,
[SHTTitle2] [varchar](50) NULL,
[SHTTitle3] [varchar](50) NULL,
[SHTTitle4] [varchar](50) NULL,
[SHTDescription] [varchar](50) NULL,
[SHTNbSections] [int] NULL,
[NbMaxTasksPerSheet] [int] NULL,
[S1_PH] [varchar](30) NULL,
[S1_M] [varchar](30) NULL,
[S1_PF] [varchar](30) NULL,
[S2_PH] [varchar](30) NULL,
[S2_M] [varchar](30) NULL,
[S2_PF] [varchar](30) NULL,
[S3_PH] [varchar](30) NULL,
[S3_M] [varchar](30) NULL,
[S3_PF] [varchar](30) NULL,
[SHTFooterTitle1] [varchar](50) NULL,
[SHTFooterTitle2] [varchar](50) NULL,
[SHTFooterTitle3] [varchar](50) NULL,
[SHTFooterTitle4] [varchar](50) NULL,
[SHTFooterTitle5] [varchar](50) NULL,
[SHTFooterTitle6] [varchar](50) NULL,
[SHTFooterTitle7] [varchar](50) NULL,
[SHTFooterTitle8] [varchar](50) NULL,
[SHTFooterTitle9] [varchar](50) NULL,
[SHTFooterTitle10] [varchar](50) NULL,
[SHTFooterTitle11] [varchar](50) NULL,
[SHTFooterTitle12] [varchar](50) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [data].[TEMP_TAB_SHEET_U17] ADD DEFAULT ((0)) FOR [Phase]
GO
Query completed running with the error :
Msg 2714, Level 16, State 6, Line 2
There is already an object named 'TEMP_TAB_SHEET_U17' in the database.
Msg 1781, Level 16, State 1, Line 2
Column already has a DEFAULT bound to it.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.
How to solve this problem.
Thank you in advance.
Awan
Have you tried to set the constrain on creation:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [data].[TEMP_TAB_SHEET_U17](
[TAL] [varchar](30) NULL,
[Phase] [smallint] NOT NULL DEFAULT 0,
...
....
GO
SET ANSI_PADDING OFF
GO

SSIS get all data from A table that are not in B table and inserted it in table B

i have two table and i need to create SSIS package "data flow task"
table A and table B, i need to create SSIS package that always insert the data that are not in table B from table A into table B (based on badgeno in A and badgeno_ID in B ). any thought and helps plz?
CREATE TABLE [dbo].[A](
[firstname] [nvarchar](100) NULL,
[mobile] [nvarchar](50) NULL,
[note] [nvarchar](500) NULL,
[city] [nvarchar](255) NULL,
[badgeno] [nvarchar](50) NULL,
[lastname] [nvarchar](100) NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[B](
[ID] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [nvarchar](100) NULL,
[LastName] [nvarchar](100) NULL,
[DateOfBirth] [datetime] NULL,
[FirmID] [int] NULL,
[Phone] [varchar](50) NULL,
[Mobile] [varchar](50) NULL,
[EMail] [nvarchar](100) NULL,
[EmployeeNr] [nvarchar](10) NULL,
[Note] [nvarchar](500) NULL,
[PhonePrivate] [varchar](50) NULL,
[StreetAddress] [nvarchar](255) NULL,
[Zip] [nvarchar](20) NULL,
[City] [nvarchar](255) NULL,
[Data] [nvarchar](500) NULL,
[UserName] [nvarchar](50) NULL,
[Password] [nvarchar](50) NULL,
[ADGUID] [nvarchar](50) NULL,
[Language] [nvarchar](50) NULL,
[Theme] [nvarchar](30) NULL,
[DefaultZone] [int] NULL,
[Bed] [nvarchar](50) NULL,
[badgeNO_ID] [nvarchar](50) NULL,
[RegisteredBy] [nvarchar](50) NOT NULL,
[Registered] [datetime] NOT NULL,
[LastUpdatedBy] [nvarchar](50) NOT NULL,
[LastUpdated] [datetime] NOT NULL,
[DefaultView] [nvarchar](50) NULL,
[ExpandTagList] [bit] NULL,
[PrintEmergencyReport] [bit] NULL,
[EmergencyReportPath] [nvarchar](255) NULL)
Drag and drop an Execute Sql Task and put the following t-sql query in there. Jobs a gooden.
INSERT INTO [dbo].[B]
([firstname] , [mobile], [note], [City], [badgeNO_ID] , [LastName])
SELECT [A].[firstname]
, [A].[mobile]
, [A].[note]
, [A].[City]
, [A].[badgeno]
, [A].[LastName]
FROM [dbo].[A]
WHERE NOT EXISTS (SELECT 1
FROM [dbo].[B]
WHERE [dbo].[A].[badgeno] = [dbo].[B].[badgeNO_ID])
Use an SSIS Lookup Transformation with "No Match" Output
http://msdn.microsoft.com/en-us/library/ms141821.aspx
https://www.simple-talk.com/sql/ssis/implementing-lookup-logic-in-sql-server-integration-services/