declare @fromdate date declare @todate date set @fromdate='2011-12-01' set @todate='2012-11-31' print @fromdate print @todate
Got the error as "Conversion failed when converting date and/or time from character string." then i tried as below
declare @fromdate date declare @todate date set @fromdate=12-01-2011 set @todate=11-31-2012 print @fromdate print @todate
this time got the error as '' Msg 206, Level 16, State 2, Line 3 Operand type clash: int is incompatible with date Msg 206, Level 16, State 2, Line 4 Operand type clash: int is incompatible with date".
I am new to SQL and trying my hand at what I thought would be a simple query to bring back the loan products that are not HMDA reportable - hence the NOT IN and I get an error message after adding the NOT IN...I have read a lot of responses to the issue of an error message of 'Conversion failed when converting the nvarchar value' to try and solve the error - and have had no luck. Before I throw my laptop out the window..Here is the error message along with what I thought was a simple query; Conversion failed when converting the nvarchar value '80/10/10' to data type int.Here is the query;
SELECT P.ProductID, P.Name, PC.Name AS [Product Group], LP.Name AS [Loan Purpose], CASE WHEN LP.IsHMDAReportableFL = 0 THEN 'No' ELSE 'Yes' END AS [HMDA Reportable],
-- AssignedToTasks 32,'from (Select Distinct wft.*',' OVER(Order by task.TaskId desc)','','where IsActive=1 AND RecurrenceRule is null',0,5 Alter PROCEDURE [dbo].[AssignedToTasks]
@UserId varchar(15) Â , @selectClause Nvarchar(max),
CASE WHEN NULLIF(NHSNo2, '') IS NULL THEN 1 WHEN NULLIF(Surname, '') IS NULL THEN 2 WHEN NULLIF(Forename, '') IS NULL THEN 3 WHEN NULLIF(DOB, '') IS NULL OR DOB < '01/01/1900' THEN 4 WHEN NULLIF(AddressLine1, '') IS NULL THEN 5
[code]...
The above code worth great but ideally instead of returning a number Id like to return text for example
i am trying to run to get a list of computers from a table based on the available free space. I'd like to group them based on the available space, for example, up to 1 GB, 1-2 GB, etc.Â
However when i run this query, i get an error :Â Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '1GB To 2GB' to data type int.
I've imported a CSV file into a table in SQL Server 2012. It's a large file, 140,000+ rows, so I couldn't covert it to Excel first to preserve the date format due to Excel's row limit. In the CSV file, there were 3 column with date data in "31-Aug-09" format, and the import automatically transformed these in "31AUG09" format (varchar(50)) in SQL Server. Now I need to convert these 3 columns from varchar to datetime so I could work with them in date format.
I am trying to write a query that give me how many items were filed per year.
This is the error:
Conversion failed when converting the varchar value 'YEAR(1999)' to data type int.
Here is the query I am using:
SELECT COUNT (*), CASE WHEN ChargesFiledDate > 20141231 THEN 'YEAR (2015)' WHEN ChargesFiledDate > 20131231 THEN 'YEAR (2014)' WHEN ChargesFiledDate > 20121231 THEN 'YEAR (2013)' ELSE YEAR (0000)
[Code] ...
And got the same error. Â I know there is probably a better way to get this data (being that I need it from 2007 to present), but don't know how to write it.
Gurus, I have two list boxes, user can move items back n forth, from second listbox I am inserting values into a table. So far everything is working fine. Now I want to delete all the existing values from the table before inserting evertime..Please help me in this I dont know what to do. thanks kalloo
I'm trying to checking my production table table_a against a working table table_b (which i'm downlading data to)Here are the collumns i have in table_a and table_bDescription | FundID (this is not my PK) | Money I'm running an update if there is already vaule in the money collumn. I check to see if table_a matches table_b...if not i update table a with table b's value where FundID match up.What i'm having trouble on is if there is no record in table_a but there is a record in table_b. How can I insert that record into table_a? I would like to do all of this (the update and insert statement in one stored proc. if possible. )If anyone has this answer please let me know.Thanks,RB
I have created a table Table with name as Varchar and id as int. Now i have started inserting the rows like, insert into Table values ('arun',20).Yes i have inserted a row in the table. Now i have got the values " arun's ", 50. insert into Table values('arun's',20) My sqlserver is giving me an error instead of inserting the row. How will you solve this problem?
I am working on moving information from one of our databases into a newer one the company has recently setup. I am working in MS SQL Server 2012 and am trying to Inset/Update (depending on the information) a part table. I will list the two tables I am working on as Old (where I am getting the information) and New (where it is to be inserted into).
The old table has about 250 columns of information, most of which is not needed. The needed information is as follows: Name, ID, Component1, Component1_PIN,Component1_SN, Component1_Description, Component2, Component2_PIN, Component2_SN. The component section repeats up to Component12.
The new table has columns setup as such: Name, ID, Case, CasePIN, CaseSN, Case_Desc, Processor, ProcessorPIN, ProcessorSN, Processor_Description, Memory, MemoryPIN, MemorySN, Memory_Description, etc.
The issue I am having is that in the old table each component can have Case, Processor, Memory, etc in that one column. I need to insert Case, Memory, etc into the correct column in the new table while keeping intact the rest of the information.Â
Hi, I am trying to insert multiple values from another table as well as an addition value defined by me. Here's my code which is obviously incorrect at the AND statement: Insert Into table_1 (ID, Col_1, Col_2)Select ID, Col_A, Col_B From table_A AND table1.Col_3 = 'XYZ' Where table_A.Col_A IS NOT NULL
Pls advise on the correct way of constructing this statement. Many Thanks
i have a table whose Primary Key is "UserID". the sample "UserID" are M1,M2,M3,M4,B1,B2,B3 . i want that when i insert a valuse "M4" in the table ,by pressing Submit Button. it should not be at the end or at the start of table. Rather it should be next to M3. like the following M1 M2 M3 M4 M5 B1 B2 B3 i need the C# code of how to do that !!!! Thanks
I have 2 tables: Source Table - IncidentDimNew and Destination Table - IncidentDimNew with identical columns: Id and CreatedDate but the data is different.
I would like to insert distinct data from those 2 columns of 1st table into the same 2 columns into the 2nd table but I onlt want to replace the values in the 2nd table where the Created Date is > 2015-04
I compiled the code in order to get the information I want from 2 tables:
Source Table SELECT COUNT(Id), LEFT(CONVERT(VARCHAR(10)), CreatedDate, 126), 7) FROM IncidentDimNew
[Code] ...
This is the code I wrote in order to do it             INSERT INTO IncidentDim [Id]    ,[CreatedDate]    SELECT [Id] ,[CreatedDate]
FROM IncidentDimNew
where left(CONVERT(VARCHAR(10), CreatedDate, 126),7) > '2015-04'
GO
But what it does it's gives the SUM of the values in the corresponding rows where the values are not null which I don't want.
So  how do I leave the values as is from table IncidentDim and insert new values as it is from IncidentDimNew where the Created Date is > 2015-04?
I am looking for an alternate logic for below-mentioned code where I am inserting into a table and having left join with the same table
insert TABLE1([ID],[Key],[Return]) select distinct a.[ID],cat1,cat2Â from (select ID,[Key] Cat1 ,[Return] cat2 from @temp as temp) a left join TABLE1 oon a.ID= o.ID and a.Cat1 = o.[Key] and a.cat2 = o.[return] where [key] is null order by ID
Hi, I have a question regarding how to insert one column values into a table by selecting from different table..Here is the syntax.. ------------ insert into propertytable values (select lastvalue+incrementby from agilesequences where name='SEQPROPERTYTABLE', 13926, 0, 4, 1, 451, 1, 8, 1)
the first column in the propertytable will be... select lastvalue+incrementby from agilesequences where name='SEQPROPERTYTABLE' How do I do that..Help PLZ..
below is some code I use to identify where a patient has attended the ED department whilst also admitted as an Inpatient. This report works fine. However while most of the results are recording issues to be corrected some of them are real and as so can be excluded from the report.
Is there a way I can build in an exclusion table which would include: Â Â SELECT IP_ADMISSION.HeyNo AS HEYNo ,IP_ADMISSION.NHSNo2 AS NHSNo ,IP_ADMISSION.Forename AS Forename ,IP_ADMISSION.Surname AS Surname ,IP_ADMISSION.SourceAdmNatCode AS SourceAdm
the error message I get is {"Object reference not set to an instance of an object."} and it points to < Tickr As String = CType(FindControl("TickerTextbx"), TextBox).Text > this is my code": Protected Sub TickMastBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TickMastBtn.Click REM Collect variablesDim Tickr As String = CType(FindControl("TickerTextbx"), TextBox).Text Dim Comp As String = CType(FindControl("CoTextbx"), TextBox).TextDim Exch As String = CType(FindControl("ExchTextbx"), TextBox).Text REM Create connection and command objectsDim cn As New SqlConnection("Data Source=.SQLEXPRESS;AttachDbFilename=C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLDataVTRADE.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")Dim cmd As New SqlCommand cmd.Connection = cn REM Build our parameterized insert statementDim sql As New StringBuilder sql.Append("INSERT INTO TickerMaster ")sql.Append("(Ticker,Company,Exchange,) ")sql.Append("VALUES (@Tickr,@Comp,@Exch,)") cmd.CommandText = sql.ToString REM Add parameter values to command REM Parameters used to protect DB from SQL injection attacksWith cmd.Parameters .Add("Tickr", SqlDbType.Int).Value = Tickr.Add("Comp", SqlDbType.VarChar).Value = Comp .Add("Exch", SqlDbType.VarChar).Value = Exch End With REM Now execute the statement cn.Open() cmd.ExecuteNonQuery() cn.Close() End Sub
How can I accomplish the above. I need to insert distinct column from TableA to RecordProcess and col1+'Tr' to recordprocessExt.I can do it with cursor. I don't know any other way.
Also, there are other columns in Table A. I am using sql server 2005.
HiI need some help on achieving the following:I wrote a querie which collects Data out of three Tables, the Resultlooks like this:SET NOCOUNT ONDECLARE @ROWINTDECLARE @CURPTNO CURSORSET @CURPTNO = CURSORFORSELECT * FROM TEMPOPEN @CURPTNOFETCH NEXT FROM @CURPTNOINTO @ROWWHILE (@@FETCH_STATUS = 0)BEGINSELECT ONE.CYNO, ONE.ROLE, ONE.ROL_BEZ, ONE.PTNO, ONE.NOCY, TWO.TEXTAS NOCY_TEXTFROM(SELECT CY.CYNO,RE.CYNO AS RECYNO, RTRIM(RE.ROLE) AS ROLE, RTRIM(V_ROLE.TEXT) ASROL_BEZ,RE.PTNO AS PTNO, RTRIM(RE.NAME) AS SACHBEARBEITER, RE.NOCYFROM CYRIGHT OUTER JOINRE ON RE.CYNO = CY.CYNOINNER JOINV_ROLE ON RE.ROLE = V_ROLE.CODEWHERE (RE.PTNO IN(SELECT PT.PTNOFROM PTWHERE PT.PTNO IN(@ROW)AND V_ROLE.LANGUAGE = PT.CLANG))) AS ONELEFT JOIN(SELECT V_NOCY.CODE, V_NOCY.TEXTFROM V_NOCYINNER JOINPT ON PT.CLANG = V_NOCY.LANGUAGEAND PT.PTNO IN (SELECT PT.PTNOFROM PTWHERE PT.PTNO IN(@ROW))) AS TWOON ONE.NOCY = TWO.CODEFETCH NEXT FROM @CURPTNOINTO @ROWENDCLOSE @CURPTNODEALLOCATE @CURPTNOThe Result looks like this:RS1:6313,1300,Architekt,99737505,NULL,NULL2392762,100,Bauherr,99737505,NULL,NULLRS2:2693265,100,Bauherr,99756900,NULL,NULLNULL,1,Planer,99756900,2,Bauherr macht Pläne selberRS3:2691919,100,Bauherr,99755058,NULL,NULL2691962,6000,Kontakt,99755058,NULL,NULLMy Problem is, that I need to have all the Resultsets in one Table atthe end.So my further undertaking was to create a Temp Table with theexpectation to receive all the resultsets in one Step.The TSQL for this looks like that:SET NOCOUNT ONCREATE TABLE #CYRE_TEMP(CYNOINT NULL,ROLEINT NULL,ROL_BEZVARCHAR (60) NULL,PTNOINT NULL ,NOCYINT NULL,TEXTVARCHAR (60) NULL)GODECLARE @CYNOINT,@ROLEINT,@ROL_BEZVARCHAR (60),@PTNOINT,@NOCYINT,@TEXTVARCHAR (60),@ROWINT,@CURPTNOCURSORSET @CURPTNO = CURSOR FORSELECT PTNO FROM TEMPOPEN @CURPTNOFETCH NEXT FROM @CURPTNOINTO @ROWWHILE (@@FETCH_STATUS = 0)BEGININSERT INTO #CYRE_TEMP (CYNO, ROLE, ROL_BEZ, PTNO, NOCY, TEXT)VALUES(@CYNO,@ROLE ,@ROL_BEZ ,@PTNO ,@NOCY ,@TEXT)SELECT @CYNO = ONE.CYNO,@ROLE = ONE.ROLE,@ROL_BEZ = ONE.ROL_BEZ,@PTNO = ONE.PTNO,@NOCY = ONE.NOCY,@TEXT = TWO.TEXTFROM(SELECT CY.CYNO, RTRIM(RE.ROLE) AS ROLE, RTRIM(V_ROLE.TEXT) ASROL_BEZ,RE.PTNO AS PTNO, RTRIM(RE.NAME) AS SACHBEARBEITER, RE.NOCYFROM CYRIGHT OUTER JOINRE ON RE.CYNO = CY.CYNOINNER JOINV_ROLE ON RE.ROLE = V_ROLE.CODEWHERE (RE.PTNO IN(SELECT PT.PTNOFROM PTWHERE PT.PTNO =@ROWAND V_ROLE.LANGUAGE = PT.CLANG))) AS ONELEFT JOIN(SELECT V_NOCY.CODE, V_NOCY.TEXTFROM V_NOCYINNER JOINPT ON PT.CLANG = V_NOCY.LANGUAGEAND PT.PTNO IN (SELECT PT.PTNOFROM PTWHERE PT.PTNO =@ROW)) AS TWOON ONE.NOCY = TWO.CODEFETCH NEXT FROM @CURPTNOINTO @ROWENDCLOSE @CURPTNODEALLOCATE @CURPTNOSELECT * FROM #CYRE_TEMPDROP TABLE #CYRE_TEMPGOAnd the Output looks like this now:Q1:NULL,NULL,NULL,NULL,NULL,NULL2392762,100,Bauherr,99737505,NULL,NULLNULL,1,Planer,99756900,2,Bauherr macht Pläne selberCan someone help me getting all the 6 Rows into one Table as Output?I appreciate any available Help on this..Ssscha
Following SQL is to be inserted in an audit table :
INSERT INTO GLOBAL_VARIABLE_LOAD
([LOAD_ID]
,[LOAD_STATUS]
,[START_TIME]
,[END_TIME])
VALUES
(@P_LOAD_ID
,@P_LOAD_STATUS
,@P_START_TIME
,@P_END_TIME)
@P_LOAD_ID, @P_LOAD_STATUS, @P_START_TIME, @P_END_TIME are the 4 parameters mapped to global variables (At package Level) which store values mapped in a previous SQL Task in my control flow.
Following Error Message is thrown on executing the SQL Task:
Invalid object name 'GLOBAL_VARIABLE_LOAD'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Can anyone guide me as to how should I go about saving values in global variables and inserting them in a table.
Suppose you have a simple DML "execute as..." trigger that looks like this:
CREATE TRIGGER dbo.myTrigger  ON dbo.myTable  WITH Execute As Owner  AFTER INSERT AS
[code]...
which runs as "owner" so that the user inserting into "myTable" won't have the privs to edit the audit table.How does one capture the identity of the user whose insert statement caused the trigger to fire? I've tried "current_user" and "system_user" without success when "execute as ..." is used: they each return a value not related to the identity of the user running the original insert.without an "execute as" clause, what prevents a user from adding to or editing the audit table directly?
I want to produce some output for Mainframe application. For that I want to insert values from multiple table as source to a single column (huge in size)of a different table (Destination table). There may be same related records in all of the source tables with the primary key. When I export values from the source tables , each related records should be insterted to the destination table's field (multiple entries for each table). Please advise.
I am looking for a Sql query to verify the inserted values from one table(in CSV file) with another table(in sql database)
For example: I have below Values column that is present in once CSV file, after my data migration the values get stored in Results table under Message column.
I need to very whether values(1X,1Y) are inserted in Message record "successfully inserted value 1X"
Values (CSV) 1X 1Y
Results Table(SQL) CreatedDate                  Message 2015-08-04 08:45:29.203  successfully inserted value 1X 2015-08-04 08:44:29.103  TEst pass 2015-08-04 08:43:29.103  successfully inserted value 1X 2015-08-04 08:42:29.203  test point 2015-08-04 08:35:29.203  successfully inserted value 1Y 2015-08-04 08:30:29.203  Test Pass 2015-08-04 08:28:29.203  successfully inserted value 1Y
If all values are inserted:
Output: All values from values table are inserted successfully Total count of values inserted: 2 If only few values are inserted, example only 1X from Values table is inserted in Message
Example: Results Table CreatedDate    Message 2015-08-04 08:45:29.203  successfully inserted value 1X 2015-08-04 08:44:29.103  TEst pass 2015-08-04 08:43:29.103  successfully inserted value 1X 2015-08-04 08:42:29.203  test point
Output: All values from values are not inserted successfully in result table. Total count of values inserted: 1 Missing Values not inserted in results table are: 1Y
[Source - chn_employee_vew_test_txt [1]] Error: Data conversion failed. The data conversion for column "Column 42" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.".
[Source - chn_employee_vew_test_txt [1]] Error: The "output column "Column 42" (136)" failed because truncation occurred, and the truncation row disposition on "output column "Column 42" (136)" specifies failure on truncation. A truncation error occurred on the specified object of the specified component.
I using Locale (People's Republic of China) and code page of 936 (Simplied Chinese GBK) with header row delimiter {CR}{LF}.
I am using flat file import method.
Whenever the server process the Column 42 with value "11,Nanjing Rd.W, China" which contain 'comma' or '.' it will hit error importing with above message. When i manually change the column value to non comma or '.' (11 Nanjing Rd W China) in the flat file it is ok.
I am using SQL server 2005.
Please advise what need to be done to avoid this error ?
Thanks in advance and any idea or suggestion is very much appreciated as i have try to solve this issue for over a week but still not able to find any answer on it.