hello friends my one insert code lines is below :) what does int32 mean ? AND WHAT IS DIFFERENT BETWEEN ONE CODE LINES AND SECOND CODE LINES :)Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString) Dim cmd As New SqlCommand("Insert into table1 (UserId) VALUES (@UserId)", conn) 'you should use sproc instead cmd.Parameters.AddWithValue("@UserId", textbox1.text) 'your value Try conn.Open()Dim rows As Int32 = cmd.ExecuteNonQuery() conn.Close()Trace.Write(String.Format("You have {0} rows inserted successfully!", rows.ToString())) Catch sex As SqlExceptionThrow sex Finally If conn.State <> Data.ConnectionState.Closed Then conn.Close() End If End Try MY SECOND INSERT CODE LINES IS BELOWDim SglDataSource2, yeni As New SqlDataSource() SglDataSource2.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ToString SglDataSource2.InsertCommandType = SqlDataSourceCommandType.Text SglDataSource2.InsertCommand = "INSERT INTO urunlistesi2 (kategori1) VALUES (@kategori1)" SglDataSource2.InsertParameters.Add("kategori1", kategoril1.Text)Dim rowsaffected As Integer = 0 Try rowsaffected = SglDataSource2.Insert()Catch ex As Exception Server.Transfer("yardim.aspx") Finally SglDataSource2 = Nothing End Try If rowsaffected <> 1 ThenServer.Transfer("yardim.aspx") ElseServer.Transfer("urunsat.aspx") End If
Whenever something is inserted to a given table, I want to run someshell commands using xp_cmdshell. Would it be a bad idea to put thisxp_cmdshell in the INSERT trigger of this table?I understand that when using xp_cmdshell, the sql thread in questionwaits until xp_cmdshell finishes what it's doing. Does this mean ifmy xp_cmdshell call takes 30 seconds, that nobody else can insert tothis table until my xp_cmdshell and rest of the insert trigger finishup?The alternative solution seems to be frequent polling of the table inquestion; while this isn't really a great solution it would seem tocircumvent a table lock brought about by the INSERT trigger.Thoughts?Joel
Does anyone know of a way to make BULK INSERT or bcp ignore blank lines in the file? I am having trouble with a bunch of data files coming back with 1 or 2 blank lines at the end, and it causes the entire bcp to fail.
I suppose I could write a utility to trim the files but that seems a bit overkill. Any thoughts?
I have a file with about 600,000 lines of insert statement given to me by a developer. There are basically 5 inserts into different tables for each Product or Item. Each Insert MUST run in the order specified and must complete before the next insert runs,
To complicate things further, there are triggers that fire on every insert and each trigger must complete its transaction before the next insert starts.
What is the best and most efficient way to run the inserts, while ensuring that each statement completes before the next.
Tried using Serialization but appears some of the transactions overlap and generate errors. Tried disabling the triggers but run into other problems.
At this point I am tempted to run each statement manually
I have two SSIS packages that import from the same flat file into the same SQL 2005 table. I have one flat file connection (to a comma delimited file) and one OLE DB connection (to a SQL 2005 Database). Both packages use these same two Connection Managers. The SQL table allows NULL values for all fields. The flat file has "empty values" (i.e., ,"", ) for certain columns.
The first package uses the Data Flow Task with the "Keep nulls" property of the OLE DB Destination Editor unchecked. The columns in the source and destination are identically named thus the mapping is automatically assigned and is mapped based on ordinal position (which is equivalent to the mapping using Bulk Insert). When this task is executed no null values are inserted into the SQL table for the "empty values" from the flat file. Empty string values are inserted instead of NULL.
The second package uses the Bulk Insert Task with the "KeepNulls" property for the task (shown in the Properties pane when the task in selected in the Control Flow window) set to "False". When the task is executed NULL values are inserted into the SQL table for the "empty values" from the flat file.
So using the Data Flow Task " " (i.e., blank) is inserted. Using the Bulk Insert Task NULL is inserted (i.e., nothing is inserted, the field is skipped, the value for the record is omitted).
I want to have the exact same behavior on my data in the Bulk Insert Task as I do with the Data Flow Task.
Using the Bulk Insert Task, what must I do to have the Empty String values inserted into the SQL table where there is an "empty value" in the flat file? Why & how does this occur automatically in the Data Flow Task?
From a SQL Profile Trace comparison of the two methods I do not see where the syntax of the insert command nor the statements for the preceeding captured steps has dictated this change in the behavior of the inserted "" value for the recordset. Please help me understand what is going on here and how to accomplish this using the Bulk Insert Task.
We got this little issue of passing around (updated and inserting) small dataSets (20-500 or so records) from fat clients to a remote server running .Net / SQL 2005.
Instead of trying to fudge the data and make updates in .Net, we just decided it would be a lot less nonsense if we just wrap up the dataSets in an XML string, have .Net just pass it thru as a parameter in a SP and let SQL parse it out using openXML. The data is small and server is low use, so I'm not worried about overhead, but I would like to know the best methods and DO's & Don'ts to parse the XML and make the updates/inserts....and maybe a few good examples. The few examples I've come across are kind of sketchy. Seems it's not a real popular method of handling updates.
Here is the situation, please let me know if you have any tips:..TXT files in a share at \fooSPROCS run daily parses of many things, including data on that share. Theother day, we encountered rows in the TXT files which looked like:column1Row1data,column2Row1datacolumn1Row2data,column2Row2data...etc..However, column2 was about 6000 bytes of unicode. We are bulk insertinginto a table specifying nvarchar(4000). When it encounters high unicoderows, it throws a truncation error (16).We really need information contained in the first 200 bytes of the string incolumn2. However, the errors are causing the calling SPROC to abort.Please let me know if you have any suggestions on workarounds for thissituation. Ideally, we would only Bulk Insert a sub-section of column2 ifpossible.Thanks!/Ty
I have a .txt file with the data fields below. I am trying to create a SQL query or CF statement that will convert the data into a a SQL INSERT statement. The plan would be to run the query, which would create a TEMP table to pull in the created INSERT statement, then place the TEMP table data into an already created table named FinalTable.
data1,data2,1,1 of 1,"data5",data6 data1,data2,1,1 of 1,"data5",data6 data1,data2,1,1 of 1,"data5",data6
why my insert or into is not working in my SQL Server R2 2008. I have a code I am using on an existing table and trying to put the data in a brand new table but it keeps giving me an error
select mCid, caucasian, aa, api, aian, mr, his, max(val) into memberrand from MEMBERV2_RAND cross apply ( select AA union all select API union all select AIAN union all select MR union all select HIS union all select CAUCASIAN ) v(val)
group by mCid, AA, API, AIAN, MR, HIS, caucasian ;
The error is: Msg 1038, Level 15, State 5, Line 1..An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.Do I have to actually create this table with no values first and then run the query? I was hoping this was sort of a make a table query
Hi, I am working on inserting information into a DB and then retrieving the ID created for that Data to use elsewhere in my code. I have the code below but I do not know how to get toOutput parameter. Can anyone please help?
AS INSERT INTO PRODUCTION (DATEOUT,DATEREQUIRED, PREPAREDBY, COMMENTID, TOTALQUANTITY, VENDORID, WPO, TCAPONUMBER, APPROVEDBY) VALUES( @DATEOUT, @DATEREQUIRED, @PREPAREDBY, @COMMENTID, @TOTALQUANTITY, @VENDORID, @WPO, @TCAPONUMBER, @APPROVEDBY) SET @Identity = SCOPE_IDENTITY()
'collect all the information from the form and then apply all and then update 'Get a reference to the Production table. Dim dtProduction As DataTable = DS.Tables("Production") Dim dtLineItem As DataTable = DS.Tables("LineItems") ' Create the SqlCommand to execute the stored procedure. Production.InsertCommand = New SqlCommand("dbo.InsertProduction", connection) Production.InsertCommand.CommandType = CommandType.StoredProcedure ' Add the parameter for the CategoryName. Specifying the ' ParameterDirection for an input parameter is not required. 'Production.InsertCommand.Parameters.Add("@CategoryName", SqlDbType.NVarChar, 15, "CategoryName") Production.InsertCommand.Parameters.Add("@DATEOUT", SqlDbType.DateTime, 8, "CategoryName") Production.InsertCommand.Parameters.Add("@DATEREQUIRED", SqlDbType.DateTime, 8, "CategoryName") Production.InsertCommand.Parameters.Add("@PREPAREDBY", SqlDbType.VarChar, 50, "CategoryName") Production.InsertCommand.Parameters.Add("@COMMENTID", SqlDbType.Int, 4, "CategoryName") Production.InsertCommand.Parameters.Add("@TOTALQUANTITY", SqlDbType.Int, 4, "CategoryName") Production.InsertCommand.Parameters.Add("@VENDORID", SqlDbType.Int, 4, "CategoryName") Production.InsertCommand.Parameters.Add("@WPO", SqlDbType.VarChar, 50, "CategoryName") Production.InsertCommand.Parameters.Add("@TCAPONUMBER", SqlDbType.Int, 4, "CategoryName") Production.InsertCommand.Parameters.Add("@APPROVEDBY", SqlDbType.VarChar, 50, "CategoryName") ' Add the SqlParameter to retrieve the new identity value. ' Specify the ParameterDirection as Output. Dim parameter As SqlParameter = Production.InsertCommand.Parameters.Add("@Identity", SqlDbType.Int, 0, "ProductionID") parameter.Direction = ParameterDirection.Output ' Create a new row with the same schema. Dim dr As DataRow = dtProduction.NewRow() 'you need the ID from this to insert into the Production DB ' Set the value of all the columns. dr("DateOut") = CDate(DateTimePicker1.Text) dr("DateRequired") = CDate(DateTimePicker2.Text) dr("VendorID") = CInt(vendorbox.SelectedValue) dr("HomeAddress") = txtApproved.Text.ToString dr("ApprovedBy") = txtPrepared.Text.ToString dr("TCAPO") = CInt(txtTCAPO.Text.Trim) dr("CommentID") = CommentID dr("TotalCost") = CDec(txtTotals.Text) dr("TotalQuantity") = CInt(txtQtyTotal.Text) ' Add to the Rows collection or table . dtProduction.Rows.Add(dr) 'Update the Production Table and then retrieve the ID created in this case Production.Update(dtProduction)
It seems to me that files created on Unix machines with line terminator , or chr(10), cannot be imported using the Bulk Insert statement. Is this a bug, or an oversight by Microsoft? Does this mean that unless one replaces all with , there is no way to use Bulk Insert to import Unix files? This is a very strange behavior by MSSQL. Even lessor programs such as Excel and Word automatically recognize chr(10) as a line termination character. Am I missing something, or is this just the way MSSQL is?
trying to get a new database created then running a script to created the tables, relationships, indexes and insert default data. All this I'm making happen during the installation of my Windows application. I'm installing SQL 2012 Express as a prerequisite of my application and then opening a connection to that installed SQL Server using Windows Authentication.
E.g.: Data Source=ComputerNameSQLEXPRESS;Initial Catalog=master;Integrated Security=SSPI; Then I run a query from my code to create the database eg: "CREATE DATABASE [MyDatabaseName]".
From this point I run a script using a Batch file containing "SQLCMD....... Myscriptname.sql". In my script I have my tables being created using "Use [MyDatabaseName] Go CREATE TABLE [dbo].[MyTableName] .....". So question is, should I have [dbo]. as part of my Create Table T-SQL commands? Can I remove "[dbo]."? Who would be the owner of the database? If I can remove the [dbo]., should I also remove dbo. from any query string from within my code?
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 have a table FORUM_REPLY it contain follwing fieldsquest_id,answer_id, reply_user_id.i want who is post most answer.so i need reply_user_id and max(no_of_answer).but following query given reply_user_id and no_of_answer onlySELECT reply_user_id,count(answer_id) as no_of_answer FROM FORUM_REPLY GROUP BY(reply_user_id)How to get max_no_of_answer?
I am new to the DTS game - or at least to trying to do anything other than transfer rows between databases with identical structures.
I now need to create a far more complex DTS package to transfer data between an SQL Server database (I am using SQL Server 7.0) and an Oracle database. I have no trouble in making the connections and performing simple DTS's beween the two.
However, my current task is more complicated.
Problem 1: In one database I would store fifty values as 5 five records each containing 10 values (i.e. has ten fields). However, in the other database these fifty values would all be stored as one record (i.e. one row with 50 fields). How could I go about creating a DTS to transfer this information?
Problem 2: These values should only be transfered if certain conditions are met in an another unrelated table. For example, a flag in another table indicating that transfer of the said values should occur.
Any help with either of these problems would be much appraciated.
When one of the users log into the database via a thrid party application they receive an error message:
2000/11/16 10:40:13.84spid51Error : 605, Severity: 21, State: 1 2000/11/16 10:40:13.84spid51Attempt to fetch logical page 7832 in database 'highview' belongs to object '1241055457', not to object 'application_data'. 2000/11/16 10:45:07.68spid46Getpage: bstat=0x1008/0, sstat=0x80002110, disk 2000/11/16 10:45:07.68spid46pageno is/should be:objid is/should be: 2000/11/16 10:45:07.68spid460x1e98(7832)0x49f900e1(1241055457) 2000/11/16 10:45:07.68spid460x1e98(7832)0x4810b86f(1209055343) 2000/11/16 10:45:07.68spid46... extent objid 0, mask 0/0, next/prev=0/0 2000/11/16 10:45:07.68spid46... retry bufget after purging bp 0x2da7e060
I tried running DBCC checkdb, newalloc,& checktable to fix the probelm and than droping the table and rebuilding it but not success, any suggestion are more than welcome.
If anybody can suggest the most efficient way to "page" the output from a big and wide table (about 7000000 records) in order to display on the web in the user requested sort order. Sort order could be on at least 7 different columns from 50 of returned.
I need to find a solution to move to the next and previous page.
what if I took this trigger and based it on a view rather then a table
CREATE TRIGGER TerminationUpdateTrigger ON EmployeeGamingLicense FOR UPDATE AS INSERT INTO TERMINATION(Status,[TM #],LastName, FirstName, [SocialSecurityNumber], DateHired, Title) SELECT STATUS, [TM#], LASTNAME, FIRSTNAME, [SSN#], HIREDATE, JOBTITLE FROM Inserted WHERE STATUS = 'TERMINATED'
CREATE VIEW dbo.Update_Terminations AS SELECT STATUS, TM#, LASTNAME, FIRSTNAME, SSN#, HIREDATE, JOBTITLE FROM dbo.EmployeeGamingLicense WHERE (STATUS = N'TERMINATED')
Base the Trigger on this View rather then on the Table itself????
The question is :- Which academics have the largest number of fields of interests? Return their academic number, given name, family name, institution and total number of fields they are interested in. Your must use a subquery in the sense that you must use 2 sql statements and use any of the following to connect both:-
I have a table call CLIENTE and another table call ENDERECO where the CLIENTE table has the FOREIGN KEY of the ENDERECO table.
When I try INSERT COMMAND in C# this message is show.
The instruction INSERT conflicted with a constraint of FOREIGN FUNDAMENTAL "FK_CLIENTE_ENDERECO." The conflict happened in the database "E:ARQUIVOS DE PROGRAMASMICROSOFT SQL SERVERMSSQL.1MSSQLDATALINETEC.MDF", table "dbo.I ADDRESS", column 'IDENDERECO.' The instruction was concluded.
I have number of tasks in my control flow most of them are execute sql task. I want to update one of the column in my table when anyone of the task in the control get fails?
Please let me know if anyone have an idea how to do this.
Dear Friends,I'm a junior DBA, I've to prepare an online examination. for this, I've three categories. a)beginer level b)intermediate level c)expert level
again here subjects are 6. like sqlserver,oracle,c#,vb.net,html,javascript. in these subjects, i've to select these three types of questions. now how can i design for this requirement? shall i create three tables for beginer, intermediate,expert or shall i create 6 tables and write according that?
Hi guysWe have a following problem. For security reasons in each table in ourDB we have addition field which is calculated as hash value of allcolumns in particular row.Every time when some field in particular row is changed we create andcall select query from our application to obtain all fields for thisrow and then re-calculate and update the hash value again.Obviously such approach is very ineffective, the alternative is tocreate trigger on update event and then execute stored procedure whichwill re-calculate and update the hash value. The problem with thisapproach is that end user could then change the date in the tables andthen run this store procedure to adjust hash value.We are looking for some solution that could speed up the hash valueupdating without allowing authorized user to do itThanks in advance,Leon
Having no more experience than reading books online, here is an interesting idea I would like to run by you guys and you can let me know if it is feasible or tell me I need to put the crack pipe down...
We are going to increase the number of disks in our SAN, and I was speaking with the SAN administrator and he mentioned the shuffling of logical drives to match the new space. He said he is going to have to go through quite a few combinations/permutations on figuring out the best configuration for what data goes on the old vs. new to get the optimal space.
Is this something that can be modeled out? I can write something that recursively figures it out, but why not explore fun ideas with tools that may be able to do it?
aspnet_wp!resourceutilities!5!07/11/2007-10:32:00:: i INFO: Reporting Services starting SKU: Developer aspnet_wp!resourceutilities!5!07/11/2007-10:32:00:: i INFO: Evaluation copy: 0 days left
Hi, I have a table that has the ff: LastName varchar(50) FirstName varchar(50) PhotoPath varchar(50) Now I want to create a form that can accept the LastName,Firstname and also can upload a picture which in turn the filename of the image will be the value for the PhotoPath field, and eventually displays it using the repeater control. Your Help/Info. is highly appreciated...
Last night, I have this idea, but can not know if it can have a good performance and efficiency when the @CurrentPage is big.-------------------------------------------------------------------DATABASE:AdventureWorks DECLARE @CurrentPage intDECLARE @PageSize intDECLARE @OrderExpression nvarchar(100)DECLARE @Sql nvarchar(500)SET @CurrentPage = 1SET @PageSize = 10SET @OrderExpression = N' employeeid 'DECLARE @BigTop intDECLARE @SmallTop intSET @BigTop = @CurrentPage * @PageSizeSET @SmallTop = (@CurrentPage -1) * @PageSizeDECLARE @StartTime datetimeSET @StartTime = GETDATE()SET @Sql = N' SELECT TOP (' + CAST(@BigTop AS nvarchar(10)) + ') * FROM humanresources.Employee '+ ' EXCEPT '+ ' SELECT TOP (' + CAST(@SmallTop AS nvarchar(10)) + ') * FROM humanresources.Employee ORDER BY ' + @OrderExpressionEXEC sp_executesql @SqlDECLARE @EndTime datetimeSET @EndTime = GETDATE()SELECT DATEPART(s,@EndTime-@StartTime)SELECT DATEPART(ms,@EndTime-@StartTime)GO-----------------------------------------------------------------