Insert Into Creates Two Identical Rows

Mar 13, 2008

I have an "insert into" statement that creates two identical rows in a table, with this statement:

delete from [table] where [column] = @parameter
INSERT INTO [table]
([fields])
VALUES ([parameter values])

This is the code-behind that performs the insert:

Dim dbConn As New SqlConnection(strConn)
Dim cmd As New SqlCommand("sp_CreateUser", dbConn)
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@UserID", strUserID)
cmd.Parameters.AddWithValue("@UserName", strUserName)
cmd.Parameters.AddWithValue("@Email", strEmail)
cmd.Parameters.AddWithValue("@FirstName", strFirstName)
cmd.Parameters.AddWithValue("@LastName", strLastName)
cmd.Parameters.AddWithValue("@Teacher", strTeacher)
cmd.Parameters.AddWithValue("@GradYr", lngGradYr)
Using dbConn
dbConn.Open()
cmd.ExecuteNonQuery()
dbConn.Close()
cmd.Dispose()
dbConn.Dispose()
End Using

I wonder if it inserts twice due to a postback issue. Is there a way to stop two rows from being created in the first place with the same "insert into" statement? I'd appreciate any advice.

View 3 Replies


ADVERTISEMENT

Update Only One Of Two Identical Rows

Oct 29, 2006

Hello,I ended up with two identical rows in one table. They should have differences but I cannot update one, as it tries to update both of them, or throws an error. How to update only one row, and leave other as is?

View 10 Replies View Related

Delete Only 2 Out Of 4 Identical Rows

Jun 19, 2004

I am a beginner in Ms-Sql,so kindly help me with this query:-
Following is the table:-

Name Phone email
John 4564 john@abc.com
John 4564 john@abc.com
John 4564 john@abc.com
John 4564 john@abc.com

How can i manage to delete only 2 rows out of these 4 rows

View 11 Replies View Related

Consolidating Identical Rows

Dec 4, 2007

I'm using a query to see how many times an action was recorded on a person. The query works, it returns this:

John Smith 1
John Smith 1
John Smith 1
Jane Doh 1
Jane Doh 1
Al Johnson 1

but I need it to return totals like this

John Smith 3
Jane Doh 2
Al Johnson 1


This is the query I am using:


Select Player.First_Name, Player.Last_Name, COUNT(Action.Employee_ID)
from Player INNER JOIN
PlayerVisit on PlayerVisit.Player_ID = Player.Player_ID
join Treatment on Treatment.Visit_ID = PlayerVisit.Visit_ID
join Action on Treatment.Action_ID = Action.Action_ID
group by Player.First_Name, Player.Last_Name, Action.Employee_Id;

View 4 Replies View Related

Show Difference In Pair Of Nearly Identical Rows

Sep 28, 2007

I am trying to create an exception report that will show the difference between two versions of the same row. (Combination of two different sources in sql, with source 1 having childID = 0 and the other source having childID = 1; parentID is the link between them)

The results are as follows:

ParentID - ChildID - Col1 - Col2 - Col3
1 - 0 - AA - BB - CC
1 - 1 - AA - BF - CC
2 - 0 - GG - NN - TT
2 - 1 - DE - NN - TA
3 - 0 - etc
3 - 1 - etc
4 - etc

How can I render the differences in red in RS?

View 1 Replies View Related

Merge Allmost Identical Rows For Output Table

Dec 20, 2007

I need to transform Foxpro table to SQL Server table with merging all rows into one where all column values are the same except one . For this the only column with the different values , I want them also to be merged as coma or space delimited string. The question whether SSIS is a good candidate for this kind of data munging and also would be interested to know knowing as many as possible ways of doing that. Surely I may produce Foxpro script in 5 minutes which wil do that and be a pre-processor action before SSIS starts.

View 3 Replies View Related

Finding Mismatched Rows Between Identical Tables Based On 2 Or More Cols

Jun 8, 2007

CREATE TABLE [RS_A] ([ColA] [varchar] (10)[ColB] [int] NULL)CREATE TABLE [RS_B] ([ColA] [varchar] (10)[ColB] [int] NULL)INSERT INTO RS_AVALUES ('hemingway' , 1)INSERT INTO RS_AVALUES ('vidal' , 2)INSERT INTO RS_AVALUES ('dickens' , 3)INSERT INTO RS_AVALUES ('rushdie' , 4)INSERT INTO RS_BVALUES ('hemingway' , 1)INSERT INTO RS_BVALUES ('vidal' , 2)I need to find all the rows in A which do not exist in Bby matching on both ColA and ColBso the output should bedickens 3rushdie 4So if i write a query like this , I dont get the right result setSELECT A.ColA, A.ColBFROMRS_A AINNERJOIN RS_B BONA.ColA <B.ColAORB.ColB <B.ColBBut if i do the following, i do get the right result, but followingseems convoluted.SELECT A.ColA, A.ColBFROMRS_A AWHERE ColA + CAST(ColB AS VARCHAR)NOT IN (SELECT ColA+CAST(ColB AS VARCHAR) FROMRS_B B)

View 6 Replies View Related

INSERT Creating 2 Identical Records

Nov 28, 2006

i created a simple table to record all uploaded files to my website. now, it works, but the problem is, it posts to the table 2 times, as in it executes "Button1_Click"  event twice. The result is i get two records which are the same, and only differs in primary key (because i set it as an autonumber). how do i fix this? thanks in advance
here's the code:
HTML:  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
InsertCommand="INSERT INTO [Base_Files] ([User_ID], [Date_Posted], [File_Type], [File_Size], [File_Name], [File_Description]) VALUES (@User_ID, @Date_Posted, @File_Type, @File_Size, @File_Name, @File_Description)">

<InsertParameters>
<asp:Parameter Name="User_ID" />
<asp:Parameter Name="Date_Posted" />
<asp:Parameter Name="File_Type" />
<asp:Parameter Name="File_Size" />
<asp:Parameter Name="File_Name" />
<asp:Parameter Name="File_Description" />
</InsertParameters>

</asp:SqlDataSource>
 VB:Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

If FileUpLoad1.HasFile Then FileUpLoad1.SaveAs(Server.MapPath(".") & "files" & FileUpLoad1.FileName)
Label1.Text = "Received <strong>" & FileUpLoad1.FileName & "</strong> Content Type: " & FileUpLoad1.PostedFile.ContentType & ", Length: " & FileUpLoad1.PostedFile.ContentLength & "bytes, at " & Date.Now.ToString("MMM dd, yyyy, h:mmtt")

SqlDataSource1.InsertParameters("File_Name").DefaultValue = FileUpLoad1.FileName.ToString()
SqlDataSource1.InsertParameters("User_ID").DefaultValue = User.Identity.Name.ToString()
SqlDataSource1.InsertParameters("File_Type").DefaultValue = FileUpLoad1.PostedFile.ContentType
SqlDataSource1.InsertParameters("File_Size").DefaultValue = FileUpLoad1.PostedFile.ContentLength
SqlDataSource1.InsertParameters("File_Description").DefaultValue = txtDescription.Text.ToString()
SqlDataSource1.InsertParameters("Date_Posted").DefaultValue = Date.Now.ToString("MMM dd, yyyy, h:mmtt")
SqlDataSource1.Insert()

Else
Label1.Text = "No uploaded file"
End If

End Sub

View 1 Replies View Related

Identical Database W/ Identical Stored Procedures?

Oct 25, 2005

We have written an application which splits up our customers data intotheir individual databases. The structure of the databases is thesame. Is it better to create the same stored procedures in eachdatabase or have them in one central location and use the sp_executesqland execute the generated the SQL statement.Thank you.Mayur Patel

View 4 Replies View Related

Using SSIS 2005 To Strip Out Bad Rows In Excel And Then Insert Detailed Rows Into OLE DB Data Source

Apr 6, 2006

Environment:
 
Running this code on my PC via VS 2005
.Net version 2.0.50727 on the server (shown in IIS)
Code is in ASP.NET 2.0 and is a VB.NET Console application
SSIS 2005
 
Problem & Info:
 
I am bringing in an Excel file.  I need to first strip out any non-detail rows such as the breaks you see with totals and what not.  I should in the end have only detail rows left before I start moving them into my SQL Table.  I'm not sure how to first strip this information out in SSIS specfically how down to the right component and how to actually code the component to do this based on my Excel file here: http://www.webfound.net/excelfile.xls

Then, I assume I just use a Flat File Source coponent or something to actually take the columns in the Excel and split into an OLE DB Datasource to shove each column into a corresponding column in my SQL Server Table.  I have used a Flat File Source in the past to do so with a comma delimited txt file but never tried with an Excel.
 
Desired Help:

 
How to perform
 
1)       stripping out all undesired rows
2)       importing each column into sql table

View 1 Replies View Related

Insert Rows With SQLServerce V3.5 Is Very Slow Can Anyone Help Insert Performance Poor

Feb 22, 2008



Hi All

I decided to change over from Microsoft Access Database file to the New SQLServerCe Compact edition. Although the reading of data from the database is greatly improved, the inserting of the new rows is extremely slow.

I was getting between 60 to 70 rows per sec using OLEDB and an Access Database but now only getting 14 to 27 rows per sec using SQLServerCe.

I have tried the below code changes and nothing seams to increase the speed, any help as I would prefer to use SQLServerCe as the database is much smaller and I€™m use to SQL Commands.

Details:
VB2008 Pro
.NET Frameworks 2.0
SQL Compact Edition V3.5
Encryption = Engine Default
Database Size = 128Mb (But needs to be changes to 999Mbs)

Where Backup_On_Next_Run, OverWriteQuick, CompressAns are Booleans, all other column sizes are nvarchar and size 10 to 30 expect for Full Folder Address size 260

TRY1

Direct Insert Using Data Adapter.

Me.BackupDatabaseTableAdapter1.Insert(Group_Name1, Full_Folder_Address1, File1, File_Size_KB1, Schedule_To_Run1, Backup_Time1, Last_Run1, Result1, Last_Modfied1, Last_Modfied1, Backup_On_Next_Run1, Total_Backup_Times1, Server_File_Number1, Server_Number1, File_Break_Down1, No_Of_Servers1, Full_File_Address1, OverWriteQuick, CompressAns)

14 to 20 rows per second (Was 60 to 70 when using OLEDB Access)


TRY 2

Using Record Sets

Private Sub InsertRecordsIntoSQLServerce(ByVal Group_Name1 As String, ByVal Full_Folder_Address1 As String, ByVal File1 As String, ByVal File_Size_KB1 As String, ByVal Schedule_To_Run1 As String, ByVal Backup_Time1 As String, ByVal Last_Run1 As String, ByVal Result1 As String, ByVal Last_Modfied1 As String, ByVal Latest_Modfied1 As String, ByVal Backup_On_Next_Run1 As Boolean, ByVal Total_Backup_Times1 As String, ByVal Server_File_Number1 As String, ByVal Server_Number1 As String, ByVal File_Break_Down1 As String, ByVal No_Of_Servers1 As String, ByVal Full_File_Address1 As String, ByVal OverWriteQuick As Boolean, ByVal CompressAns As Boolean)

Dim conn As SqlCeConnection = Nothing
Dim CommandText1 As String = "INSERT INTO BackupDatabase (Group_Name, Full_Full_Folder_Adress, File1,File_Size_KB, Schedule_To_Run, Backup_Time, Last_Run, Result, Last_Modfied, Latest_Modfied, Backup_On_Next_Run, Total_Backup_Times, Server_File_Number, Server_Number, File_Break_Down, No_Of_Servers, Full_File_Address, OverWrite, Compressed) VALUES ('" & Group_Name1 & "', '" & Full_Folder_Address1 & "', '" & File1 & "', '" & File_Size_KB1 & "', '" & Schedule_To_Run1 & "', '" & Backup_Time1 & "', '" & Last_Run1 & "', '" & Result1 & "', '" & Last_Modfied1 & "', '" & Latest_Modfied1 & "', '" & CStr(Backup_On_Next_Run1) & "', '" & Total_Backup_Times1 & "', '" & Server_File_Number1 & "', '" & Server_Number1 & "', '" & File_Break_Down1 & "', '" & No_Of_Servers1 & "', '" & Full_File_Address1 & "', '" & CStr(OverWriteQuick) & "', '" & CStr(CompressAns) & "')"
Try
conn = New SqlCeConnection(strConn)
conn.Open()

Dim cmd As SqlCeCommand = conn.CreateCommand()

cmd.CommandText = "SELECT * FROM BackupDatabase"
cmd.ExecuteNonQuery()
Dim rs As SqlCeResultSet = cmd.ExecuteResultSet(ResultSetOptions.Updatable Or ResultSetOptions.Scrollable)

Dim rec As SqlCeUpdatableRecord = rs.CreateRecord()

rec.SetString(1, Group_Name1)
rec.SetString(2, Full_Folder_Address1)
rec.SetString(3, File1)
rec.SetSqlString(4, File_Size_KB1)
rec.SetSqlString(5, Schedule_To_Run1)
rec.SetSqlString(6, Backup_Time1)
rec.SetSqlString(7, Last_Run1)
rec.SetSqlString(8, Result1)
rec.SetSqlString(9, Last_Modfied1)
rec.SetSqlString(10, Latest_Modfied1)
rec.SetSqlBoolean(11, Backup_On_Next_Run1)
rec.SetSqlString(12, Total_Backup_Times1)
rec.SetSqlString(13, Server_File_Number1)
rec.SetSqlString(14, Server_Number1)
rec.SetSqlString(15, File_Break_Down1)
rec.SetSqlString(16, No_Of_Servers1)
rec.SetSqlString(17, Full_File_Address1)
rec.SetSqlBoolean(18, OverWriteQuick)
rec.SetSqlBoolean(19, CompressAns)
rs.Insert(rec)
Catch e As Exception
MessageBox.Show(e.Message)
Finally
conn.Close()
End Try
End Sub

€™20 to 24 rows per sec

TRY 3

Using SQL Commands Direct

Private Sub InsertRecordsIntoSQLServerce(ByVal Group_Name1 As String, ByVal Full_Folder_Address1 As String, ByVal File1 As String, ByVal File_Size_KB1 As String, ByVal Schedule_To_Run1 As String, ByVal Backup_Time1 As String, ByVal Last_Run1 As String, ByVal Result1 As String, ByVal Last_Modfied1 As String, ByVal Latest_Modfied1 As String, ByVal Backup_On_Next_Run1 As Boolean, ByVal Total_Backup_Times1 As String, ByVal Server_File_Number1 As String, ByVal Server_Number1 As String, ByVal File_Break_Down1 As String, ByVal No_Of_Servers1 As String, ByVal Full_File_Address1 As String, ByVal OverWriteQuick As Boolean, ByVal CompressAns As Boolean)

Dim conn As SqlCeConnection = Nothing
Dim CommandText1 As String = "INSERT INTO BackupDatabase (Group_Name, Full_Full_Folder_Adress, File1,File_Size_KB, Schedule_To_Run, Backup_Time, Last_Run, Result, Last_Modfied, Latest_Modfied, Backup_On_Next_Run, Total_Backup_Times, Server_File_Number, Server_Number, File_Break_Down, No_Of_Servers, Full_File_Address, OverWrite, Compressed) VALUES ('" & Group_Name1 & "', '" & Full_Folder_Address1 & "', '" & File1 & "', '" & File_Size_KB1 & "', '" & Schedule_To_Run1 & "', '" & Backup_Time1 & "', '" & Last_Run1 & "', '" & Result1 & "', '" & Last_Modfied1 & "', '" & Latest_Modfied1 & "', '" & CStr(Backup_On_Next_Run1) & "', '" & Total_Backup_Times1 & "', '" & Server_File_Number1 & "', '" & Server_Number1 & "', '" & File_Break_Down1 & "', '" & No_Of_Servers1 & "', '" & Full_File_Address1 & "', '" & CStr(OverWriteQuick) & "', '" & CStr(CompressAns) & "')"

Try
conn = New SqlCeConnection(strConn)
conn.Open()

Dim cmd As SqlCeCommand = conn.CreateCommand()
cmd.CommandText = CommandText1
'cmd.CommandText = "INSERT INTO BackupDatabase (€¦"
cmd.ExecuteNonQuery()

Catch e As Exception
MessageBox.Show(e.Message)
Finally
conn.Close()
End Try
End Sub

€˜ 25 to 30 but mostly holds around 27 rows per sec I

Is this the best you can get or is there a better way. Any help would be greatly appericated

Kind Regards

John Galvin

View 3 Replies View Related

Force An INSERT INTO To Insert Rows Orderly

Apr 25, 2007

Hi All,

From what I know, when you execute an
INSERT INTO table1 (field0)
SELECT field0 FROM table 2 ORDER BY field0
the rows are inserted in whatever order the server engine thinks is better at that moment. Is it any way I can have field0 in table1 inserted in the order I need?

My problem is that I can not touch table1, it is used by a legacy application which I am not allowed to modify. I was thinking about creating a clustered index, adding an id field, etc, but I can not know how this will affect the front end application.

table1 and table2 have only a few hundred records.

table1 =
CREATE TABLE [FinalPlasma] ([name] [varchar] (2000) NULL )

table2 =
CREATE TABLE [Test_FinalPlasma] ([nameID] [int] NOT NULL ,
[name] [varchar] (2000) NULL
)
The update that is not giving the "good" order =

DELETE FROM FinalPlasma
INSERT INTO FinalPlasma SELECT name from dbo.Test_FinalPlasma

Unfortunately I can not order the [name] field after the update, because it looks something like

Donald McQ. Shaver
Mark Sheilds
R.J. Shirley
W.E. Sills
Kenneth A. Smee
A. Britton Smith
LCol Edward W. Smith
Harry V. Smith
M. E. Southern
Timothy A. Sparling
Spectrum Investment Management Limited


Thank you,

View 12 Replies View Related

SQL Server 2008 :: Insert Data Into Table Variable But Need To Insert 1 Or 2 Rows Depending On Data

Feb 26, 2015

I am writing a query to return some production data. Basically i need to insert either 1 or 2 rows into a Table variable based on a decision as to does the production part make 1 or 2 items ( The Raw data does not allow for this it comes from a look up in my database)

I can retrieve all the source data i need easily but when i come to insert it into the table variable i need to insert 1 record if its a single part or 2 records if its a twin part. I know could use a cursor but im sure there has to be an easier way !

Below is the code i have at the moment

declare @startdate as datetime
declare @enddate as datetime
declare @Line as Integer
DECLARE @count INT

set @startdate = '2015-01-01'
set @enddate = '2015-01-31'

[Code] .....

View 1 Replies View Related

Trigger That Creates Folder

Jan 18, 2005

Does anyone know if it is possible (and if yes, how) to create a trigger that creates a folder for every inserted record?
In a specific root folder, I want a subfolder for every record in the table. How does the trigger have to look like to make the folder automatically with every insert of a new record???

thanks!!

View 3 Replies View Related

Upsizing Creates Huge MSSQL

Feb 1, 2005

I am upgrading a .mdb to MSSQL. The .mdb is 17MB, but the resulting MSSQL is 72MB. Tried using both the Access Upsizing Wizard and Enterprise Manager DTS. I have done this a number of times before, but never ran into this problem. Any ideas what coule be going on, and how to fix it?

View 2 Replies View Related

Upsizing Creates Huge MSSQL

Feb 1, 2005

I am upgrading a .mdb to MSSQL. The .mdb is 17MB, but the resulting MSSQL is 72MB. Tried using both the Access Upsizing Wizard and Enterprise Manager DTS. I have done this a number of times before, but never ran into this problem. Any ideas what coule be going on, and how to fix it?

View 1 Replies View Related

A Function That Creates A View (dynamic SQL)

Jan 23, 2008

I'm very new to SQL Server. Please help. I need to create a FUNCTION that creates a view. Then call this function in a SQL which is passed as a parameter to BCP. In Oracle, it would be something like:



create function CREATEVIEW

return number as

begin

create view SampleView as SELECT a,b,c from Mytable;

return 1;

when others then return 0; -- for exception handling

end:



create function DROPVIEW

return number as

begin

Drop view SampleView;

return 1;

when others then return 0; -- for exception handling

end:



Then my BCP will have something like:



BCP "select CREATEVIEW from dual"... QUERYOUT ..



then

BCP "select * from SampleView"... QUERYOUT ..



then drop the view again:

BCP "select DROPVIEW from dual"... QUERYOUT ..



I know there is no DUAL table in SQL SERVER. I just want to know how to code this in SQL Server.

The origin of my problem is that my SQL statement is too long to fit as BCP parameter, hence, am creating a view and reading there and dropping it again. If you can provide me with a better workaround, that would be great.
Thanks in advance.

View 7 Replies View Related

SSIS Creates SQL DUMP File

Mar 22, 2007

I have several SSIS packages which are run in sequence. But some strange reason sometimes a SQL Dump is created. If I restore database and restart the same ETL is works, or it creates another SQL Dump in a different place. Any idea on how to debug this problem?

SQL Server 2005 Developer Edition SP1 ( should I upgrade to SP2? )
Windows 2003/r2 64b ( latest patches )

Eventlog
Bucket 09193120, bucket table 5, EventType sql90exception64, P1 dtsdebughost.exe, P2 2005.90.1399.0, P3 0000000043500d1e, P4 ntdll.dll, P5 5.2.3790.1830, P6 0000000042438b79, P7 0, P8 000000000003d5a8, P9 0000000000000000, P10 NIL.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

SQL Dump file
03/21/07 17:55:11, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Input parameters: 4 supplied
03/21/07 17:55:11, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ProcessID = 5928
03/21/07 17:55:11, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ThreadId = 0
03/21/07 17:55:11, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Flags = 0x0
03/21/07 17:55:11, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDumpFlags = 0x0
03/21/07 17:55:11, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, SqlInfoPtr = 0x000000000100FAF8
03/21/07 17:55:11, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, DumpDir = <NULL>
03/21/07 17:55:11, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExceptionRecordPtr = 0x0000000000000000
03/21/07 17:55:11, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ContextPtr = 0x0000000000000000
03/21/07 17:55:11, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExtraFile = <NULL>
03/21/07 17:55:11, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, InstanceName = <NULL>
03/21/07 17:55:11, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ServiceName = <NULL>
03/21/07 17:55:11, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 11 not used
03/21/07 17:55:12, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 7 not used
03/21/07 17:55:12, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDump completed: C:Program FilesMicrosoft SQL Server90SharedErrorDumpsSQLDmpr0053.mdmp
03/21/07 17:55:12, ACTION, DtsDebugHost.exe, Watson Invoke: Yes
03/21/07 17:55:12, ACTION, DtsDebugHost.exe, Watson Invoked: C:PROGRA~1COMMON~1MICROS~1DWDW20.EXE dw20.exe -d "C:Program FilesMicrosoft SQL Server90SharedErrorDumpsSQLDmpr0001.mft"

Versions

Microsoft Visual Studio 2005 Version 8.0.50727.762 (SP.050727-7600)
Microsoft .NET Framework Version 2.0.50727

Installed Edition: IDE Standard
Microsoft Visual Studio 2005 Premier Partner Edition - ENU Service Pack 1 (KB926601)
This service pack is for Microsoft Visual Studio 2005 Premier Partner Edition - ENU.
If you later install a more recent service pack, this service pack will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/926601

SQL Server Analysis Services Microsoft SQL Server Analysis Services Designer Version 9.00.2047.00
SQL Server Integration Services Microsoft SQL Server Integration Services Designer Version 9.00.2047.00
SQL Server Reporting Services Microsoft SQL Server Reporting Services Designers Version 9.00.2047.00

View 3 Replies View Related

Sql Stored Procedure - Proc Creates Query

Jan 11, 2007

Is it possible to pass 5 variables to a proc and have IT do the thinking and query structuring?
An example of what I'm try to do is have one proc for getting vehicles by make, model, and years
example of what I'd like to accomplish:veh_list_vehicleInfo_byDetails
@TypeID int,
@MakeID int,
@ModelID int,
@begYear int,
@endYear int
AS
BEGIN

declare @SQL as nvarchar(500)
set @SQL = 'SELECT a.ID, b.Model, c.Make, d.Name, a.Year, a.Mileage, a.Price, a.Sale, a.Certified_Pre_Owned FROM veh_vehicles a INNER JOIN veh_model b ON a.ModelID = b.ID INNER JOIN veh_make c ON a.MakeID = c.ID INNER JOIN veh_location d ON a.LocationID = d.ID'

decalre @ATTRIBUTES as nvarchar(500)
if @TypeID is not null AND @TypeID > 0
begin
set @ATTRIBUTES = @ATTRIBUTES + ' a.TypeID = ' + @TypeID
end
if @MakeID is not null AND @MakeID > 0
begin
set @ATTRIBUTES = @ATTRIBUTES + ' a.MakeID = ' + @MakeID
end

....etc etc.......

if Len(@ATTRIBUTES) > 0
begin
EXEC(@SQL + ' WHERE ' + @ATTRIBUTES)
End
Else
BEGIN
EXEC(@SQL)
END

END
 But I keep getting some errors regarding converting 'a.TypeID = ' to int
?????  Please help!!
 I figured this would be easier than writing stored procs for EACH situation

View 2 Replies View Related

Executing Dts Package Through Asp.net Creates Tables But No Data!

Sep 25, 2007

hey out there,
just started playing with this so bare with me...
i've used the data export wizard to create a dts package in sql server 2000. the package takes selected tables, creates an access database and then dumps all the data into the tables.
it works fine when i run the package in enterprise manager, but when i call it from asp.net (vb.net) the access database gets created, the tables are created but it fails to dump the data!
this is my code:1 Public Sub executeDts()
2
3 Dim oPkg As DTS.Package2
4 oPkg = New DTS.Package2
5 Dim oStep As DTS.Step
6 Dim sMessage As New StringBuilder
7
8
9 oPkg.LoadFromSQLServer("serverNameHere", "userNameHere", "passwordHere", DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, , , , "packageNameHere")
10
11 For Each oStep In oPkg.Steps
12
13 sMessage.Append("<p> Step [" & oStep.Name & "] ")
14
15 If oStep.ExecutionResult = DTSStepExecResult.DTSStepExecResult_Failure Then
16
17 sMessage.Append(" failed<br>")
18
19 Else
20
21 sMessage.Append(" succeeded<br>")
22
23 End If
24
25 sMessage.Append("Task """ & oPkg.Tasks.Item(oStep.TaskName).Description & """</p>")
26
27 Next
28
29 Response.Write("sMessage = " & sMessage.ToString & "<br/>")
30
31 oPkg.Execute()
32
33 oPkg.UnInitialize()
34
35 oPkg = Nothing
36
37 End Sub
38

am i missing a step?! it seems very odd that the tables are created but the insert fails...
any advice anyone can offer would be great!
cheers,
jake

View 2 Replies View Related

CHange Of Server Name Creates Agent Problem

May 30, 2002

Hi.
I've installed and configured a SQL Server 2000 box on our local network. Now that I've moved it up to the Live network I've had to change it's name and IP.
Everything is fine apart from the SQL Server Agent, specifically the maintenance plans and jobs.
When I go to change or delete the existing plans or jobs I have the following message:
Microsoft SQL-DMO (ODBC SQL State: 42000)
Error 14274: Cannot add, update or delete a job (or it's steps or schedule) that originated from an MSX Server.

In typical MS style, I have actually been able to delete the maintenance plans from the "Maintenance Plans" area and create new ones. However I am unable to delete the related jobs under the SQL Server Agent - Jobs menu.

As far as I'm aware I have never added a Master SQL Agent Server (MSX) and looknig under the Agent properties - Job System it does say (none).

Any help very much appreciated.

Simon Call

View 1 Replies View Related

.Update Creates New Record But All Fields Null

Jan 26, 2006

Hi guys, I have made several Access-based CMSs but now I am using SQL Server. I can read the records but my first attempts at writing are resulting in new records (with new ID) but all the fields are null.
I am posting the data from a form to the same page and an if /then statement catches the flag in the URL and runs the update script below. All the field names are correct.
if request.QueryString("add")<> "" then
Dim rsUpdateEntry
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")
rsUpdateEntry.Open "SELECT * from generic_country_info" , oConn, 2, 3

rsUpdateEntry.AddNew

rsUpdateEntry.Fields("title1") = Request.Form("title1")
rsUpdateEntry.Fields("body1") = Request.Form("body1")
rsUpdateEntry.Fields("title2") = Request.Form("title2")
rsUpdateEntry.Fields("body2") = Request.Form("body2")
rsUpdateEntry.Fields("title3") = Request.Form("title3")
rsUpdateEntry.Fields("body3") = Request.Form("body3")
rsUpdateEntry.Fields("title4") = Request.Form("title4")
rsUpdateEntry.Fields("body4") = Request.Form("body4")
rsUpdateEntry.Fields("title5") = Request.Form("title5")
rsUpdateEntry.Fields("body5") = Request.Form("body5")
rsUpdateEntry.Fields("image1") = Request.Form("attach1")
rsUpdateEntry.Fields("image2") = Request.Form("attach2")
rsUpdateEntry.Fields("image3") = Request.Form("attach3")
rsUpdateEntry.Fields("image4") = Request.Form("attach4")
rsUpdateEntry.Fields("image5") = Request.Form("attach5")
rsUpdateEntry.Fields("country") = Request.Form("country")
rsUpdateEntry.Fields("dest_url") = Request.Form("dest_url")


rsUpdateEntry.Update

rsUpdateEntry.Close
Set rsUpdateEntry = Nothing
end if
Thanks
Mark

View 1 Replies View Related

64Bit - Creates Program Files Folder - Why?

Aug 30, 2007

We noticed SQL Server 2005 is creating Program FilesCommon FilesMicrosoft SharedDW on our largest drive for each 64-bit installation. Does anyone know what this is? It appears there is no Microsoft documentation regarding this installation and if we need to keep it. It may be .NET related, but I have no idea why it is needed.

Dave

View 5 Replies View Related

Database Script Creates Huge Log File

Mar 20, 2008

I am creating a database for an application through script. After the tables, views, and sp's are created, the database is populated with data. After all of this (and before the application is even run), the log file is about 700MB. If I shrink the database, it takes the log down to 1MB. The mdf file is about 165 MB before and after it has been shrunk.

I have two questions:
1. Is there something I should look for in my database scripts or is there a setting that could prevent this from being created so large.

2. Is there a script I can run in my sql code after the database has been created and populated to shrink it.

Thank you for your help

View 2 Replies View Related

Dynamic T-SQL Query Creates Table At Run Time.

Aug 1, 2007

The following are the output lines from my code which is constructing some T-SQL queries on the fly. The query highlighted in yellow is the problem query. The code upto the problem query is working correctly and I am able to see the output tables in the Query Analyzer


STEP 1 : Create 3 Tables In Dynamic T-SQL : Showing 3 Strings from Exec statement

Create Table ##Test_word28July2007185548990201 ( t float, e float, s float, word varchar(80) )
Create Table ##OUT_Test_word28July2007185548990201 ( t float, e float, s float, word varchar(80), KeywordID int, rank float )
Create Table ##STVR_FLOAT_Test_word28July2007185548990201 ( var_val float)


Step 2: Retrieving A Value Into Another Global Table (table has only 1 row and 1 column)
Insert Into ##STVR_FLOAT_Test_word28July2007185548990201 ( var_val ) Select IsNull( t , 0 ) from ##Test_word28July2007185548990201
(1 row(s) affected)

Step 3: I need the value (var_val) in ##STVR_FLOAT_Test_word28July2007185548990201
Update ##Out_Test_word28July2007194827580759 Set t = Select var_val from ##STVR_FLOAT_Test_word28July2007194827580759 where t > Select var_val from ##STVR_FLOAT_Test_word28July2007194827580759
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'Select'.
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'Select'.
(1 row(s) affected)



Problem Definition

Part 1

The update query is trying to retrieve a value in a dynamically constructed table. ##STVR_FLOAT_Test_word28July2007185548990201 (1 column var_val , 1 row)

Update <Table_Name> set t = @var_val where t > @var_val
The update query is simple, except I need to "SELECT" @var_val from the dynamic table


The @var_val is a float value.

I have outputted the contents of the table that is holding the @temp_val variable
It has the correct value and the table has only 1 row and 1 column.

WHAT IS THE SYNTAX OF A QUERY TO SELECT A SINGLE VALUE FROM A TEMP TABLE WITH ONLY 1 ROW OR COLUMN AND USE THE SELECTED VALUE AS A VARIABLE IN AN UPDATE STATEMENT

View 5 Replies View Related

Stored Procedure That Creates A View In Another Database

Apr 18, 2008

Hi,

I want to run a stored procedure in Database A that will create a View on a table in database B. Is that possible?


Example (Creating a Stored Procedure in Database A):

create procedure test
as
begin

use B
create view Vjobs
as
select * from jobs
end


This does not work because you are not allowed "USE" in a Stored Procedure.

Please help.

View 1 Replies View Related

Exporting Reports Creates A Blank Window

Nov 15, 2006

I have created a few reports and linked them to a URL on a web page. (sample link is : http://servername/ReportServer/Pages/ReportViewer.aspx?%2fMy_Reports%2fBacklog+Report&rs:Command=Render )

When the user clicks on the link above it renders correctly but when the user tries to export the report to any format on the list, it launches another window with the following URL : http://servername/ReportServer/Reserved.ReportViewerWebControl.axd?ExecutionID=czq4c355dmsxdy55dif1nm55&ControlID=ad74d68e-2a9c-430f-8655-dd0e6c46f831&Culture=1033&UICulture=9&ReportStack=1&OpType=Export&FileName=Backlog+Report&ContentDisposition=OnlyHtmlInline&Format=EXCEL

which then prompts the user to Open or Save the report.

How do I stop this window from opening ? or how can I make it close automatically ?

Please advise.

I know if I can change the ContentDisposition somehow to AlwaysInline then this extra window will not show during the export but it keeps defaulting to OnlyHTMLInline for ContentDisposition.

Thanks in advance.

AL

View 2 Replies View Related

Turkish Character I Creates Problem In My Query

Oct 9, 2006

Dear all,

i am using SQL server for turkish language and i have a problem with turkish character "i". Whenever "i" comes in any word of query it gives wrong result. It also not able to recognize the small and capital "i" of turkish.

View 1 Replies View Related

Using CREATE TABLE DDL On Excel Creates Two Tables

Mar 11, 2008

Hello. I am using OLEDB 4.0 to create an excel file and store DataTable rows into it. I am using

CREATE TABLE [SheetName] ([Column1] longtext, [Column2] longtext....

DDL and then write data using INSERT INTO ... DDL.

There are three strange things that i've encountered and will be glad to get help from anyone:



If I use as a table name expression with spaces, the name is changed to expression with underscore '_' symbol instead of spaces.
I can not set trailing '$' when creating a table, but when inserting data I have to use the name with traling '$' otherwise the exception is thrown. Moreover, if i get the scheme of the Excel file later I am getting TWO tables instead of one: a first with the name without '$' and another the same with trailing '$'. Nedless to say that visually Excel shows only a name without '$'
If I am trying to do same operations using OLEDB 12.0 (Office2007) I get invalid file.
If anyone knows how I can overcome above issues, please write me a code. I am coding in C# but VB examples are as good as any other.

View 5 Replies View Related

Compact Edition Creates Too Many DB's And Doesn't Save To The Original

Apr 22, 2008



So i am trying to make a simple database and with one table and use a gui to make rows.
When i run the program in debug mode it creates a new copy of my DB in the debug folder and saves only their, i cannot find a way to save back to the original DB no matter what i do including changing the Copy to Output Directory.

Now the more i try to fix this the more new DB it creates one in the Release Folder, one in the bin/Debug/bin/Debug
one in bin/Release/bin/Release.

I am going crazy trying to scoure the entire project looking for someplace i can fix this.

All i want is to create a DB and be able to make changes to it and only it.

Does anyone have any solutions to this?

Thank you for your time

View 2 Replies View Related

Transact SQL :: Script That Creates User Mapping For Network Service

Aug 20, 2015

SQL script that creates a User Mapping for NT AUTHORITYNETWORK SERVICE to a database?

View 3 Replies View Related

Script Destination Component Code Sample Here That Creates A Csv Or Xml File

Jul 11, 2006

After much work and thanks to all of you who helped on this here is a code sample that can be adapted. From the dataflow task add an OLEDB source component, a row count component and finally a Script Destination Component.

On the Script Destination Component rename the Input node of the imports and outputs tree view to "ParsedInput"

The readonly User: variables that start with gs can be read in the PreExecute method

The readwrite User: variable giSuccessCount can only be used in the post execute task because it is populated by the Row Count Component which is the previous object in the Dataflow

The xml code is adapted from an idea in Donald Farmers book

enjoy

Dave

Now if someone can make a Script Source Component that can read a file with a header , data body and trailer that would b egreat!
' Microsoft SQL Server Integration Services user script component
' This is your new script component in Microsoft Visual Basic .NET
' ScriptMain is the entrypoint class for script components
 
Imports System
Imports System.Data
Imports System.Math
Imports System.IO
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Imports System.Xml
 
Public Class ScriptMain
    Inherits UserComponent
    Dim sw As StreamWriter
    'In addition to using the Imports System.Xml statement a reference must be added to the
    'System.Xml assembly  (Select Project-Add Reference from IDE)
    Dim xWriter As XmlTextWriter
    Dim OutputFileType As String '.csv or .xml
 
 
 
    Public Overrides Sub PreExecute()
       
        'Read Only variables
        Dim gsPickUp As String = Me.Variables.gsPickUp 'D:ftprootOutAvid'
        Dim gsPickUpFilename As String = Me.Variables.gsPickUpFilename '1_AVID_'
        Dim gsPickUpFileExtn As String = Me.Variables.gsPickUpFileExtn '.csv'
        Dim gsMemoText As String = Me.Variables.gsMemoText 'Memo Text : credit adjustment'
        Dim gsStatementText As String = Me.Variables.gsStatementText 'Statment Text : credit adjustment'
        Dim gsRunMode As String = Me.Variables.gsRunMode 'UPDATE'
        Dim fileName As String = gsPickUp & "" & gsPickUpFilename
        fileName = fileName & (Format(Now(), "yyMMdd").ToString)
        'MsgBox(fileName)
 
        OutputFileType = gsPickUpFileExtn
        If OutputFileType = ".csv" Then
            fileName = fileName & gsPickUpFileExtn
            sw = New StreamWriter(fileName) 'connection to dest file
 
            'Header records
            sw.Write(gsRunMode)
            sw.Write(Environment.NewLine) ' end of line
            sw.Write(gsMemoText)
            sw.Write(Environment.NewLine)
            sw.Write(gsStatementText)
            sw.Write(Environment.NewLine)
            sw.Write(Environment.NewLine) 'Spacer
        End If
 
        If OutputFileType = ".xml" Then
            fileName = fileName & gsPickUpFileExtn
            'xWriter = New XmlTextWriter(Me.Connections.XMLConnection.ConnectionString, Nothing)
            'xWriter.WriteStartDocument()
            'xWriter.WriteComment("Customer file parsed using script")
            'xWriter.WriteStartElement("x", "customer", "http://some.org/name")
            'xWriter.WriteAttributeString("FileName", Me.Connections.XMLConnection.ConnectionString)
            xWriter = New XmlTextWriter(fileName, Nothing)
            xWriter.WriteStartDocument()
            xWriter.WriteComment("Customer file parsed using script")
            xWriter.WriteStartElement("x", "customer", "http://some.org/name")
            xWriter.WriteAttributeString("FileName", fileName)
        End If
 
 
    End Sub
 
 
 
    Public Overrides Sub ParsedInput_ProcessInputRow(ByVal Row As ParsedInputBuffer)
 
 
        If OutputFileType = ".csv" Then
            Dim delim As String = ","
 
            sw.Write(Row.ProjectID.ToString + delim)
            sw.Write(Row.TransactionRefNum.ToString + delim)
            sw.Write(Row.CustomerNum.ToString + delim)
            sw.Write(Row.AccountNum.ToString + delim)
                         
            sw.Write(Environment.NewLine) ' end of line
            sw.Flush() 'send the stream to file
        End If
 
 
 
        If OutputFileType = ".xml" Then
            xWriter.WriteStartElement("CUSTOMER")
 
            xWriter.WriteStartElement("ProjectID")
            xWriter.WriteString(Row.ProjectID.ToString)
            xWriter.WriteEndElement()
 
            xWriter.WriteStartElement("TransactionRefNum")
            xWriter.WriteString(Row.TransactionRefNum.ToString)
            xWriter.WriteEndElement()
 
            xWriter.WriteStartElement("CustomerNum")
            xWriter.WriteString(Row.CustomerNum.ToString)
            xWriter.WriteEndElement()
 
            xWriter.WriteStartElement("AccountNum")
            xWriter.WriteString(Row.AccountNum.ToString)
            xWriter.WriteEndElement()
 
             
 
        End If
 
 
 
       
       
    End Sub
 
    Public Overrides Sub PostExecute()
 
       
 
        If OutputFileType = ".csv" Then
            'Create the trailer
            sw.Write(Environment.NewLine) ' blank line
            sw.Write("RECORD_COUNT: " & Me.Variables.giSuccessCount.ToString) 'ReadWrite Varible
            sw.Write(Environment.NewLine)
            sw.Flush() 'send the stream to file
            'Close file
            sw.Close()
        End If
 
        If OutputFileType = ".xml" Then
            xWriter.WriteStartElement("RecordCount")
            xWriter.WriteString(Me.Variables.giSuccessCount.ToString)
            xWriter.WriteEndElement()
            xWriter.WriteEndElement()
 
            xWriter.WriteEndDocument()
            xWriter.Close()
        End If
 
    End Sub
 
 
End Class
 
 
 



 

View 6 Replies View Related

Jdbc Driver Creates New Thread For Each Statement With A Query Timeout Set

Jun 20, 2007

I am profiling a web application that is using the Microsoft JDBC driver, version 1.1 to connect to a sql server 2005 database. Each java.sql.Statement that is created, within the application, gets a query timeout value set on it ( statement.setQueryTimeout(...) ).

I have discovered that the JDBC driver creates a new thread to monitor each Statement and the query timeout value. When the application is under load these threads are getting created faster then they are being destroyed and I am concerned that this will cause a performance problem in production.

One option I have is to remove the query timeout value and the monitor threads will not be created, another is to change JDBC drivers.

I'm curious is there any way to control this behavior so that these threads are not created or are managed more efficiently. Is there a workaround that anyone is aware of? Is this considered a bug?

I have found a similar bug here for the 2000 driver:
http://support.microsoft.com/default.aspx/kb/894552

Cheers

View 5 Replies View Related







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