Showing posts with label rows. Show all posts
Showing posts with label rows. Show all posts

Friday, March 30, 2012

Help!!!!--Problems about the multi column report!

I have a 2 coulmns report ,one group ,when I print the report,it does not paging correctly.For example,suppose every column can display 20 rows, if every group has 20-40 rows ,the print is ok,it can paging correctly,but if one group has 10 rows or more than 40 and less than 60,the two groups will print on one paper,how can I print the every group on different paper?

Any advice would be much appreciated.

Thanks.

No one can answer me?|||

Garlic,

You can edit your group properties, On your group, right click, select edit group, on General tab, select "Page break at start" this should give you a new page for each group change.

Wednesday, March 28, 2012

Help! T-SQL, Calling multiple stored procs?

I have to load a webpage table up with values from a database as such:

The Webpage Expects a Final result set of rows with 5 columns each built as below:

For each Row Returned by StoredProc1

Write Columns 1-3 = StoredProc2

Write Column 4 = StoredProc3

Write Column 5 = StoredProc4

Next Row


But I am not sure how to write the conditionals to CALL the stored procs i wrote and loop by a return value from StoredProc1.

Any help is much appreciated!

THANKS!

I would prefer to create separate stored proc with entire logic encapsulated within it, if I were you. Loops are fast and typical in client languages, but in SQL it's better not to be overused.|||So create just one big stored proc to do it all?
|||Yes. And calling stored procs from within stored procs is not so fast.|||

Can you be a little more specific about what each stored proc does? I mean, if it is a set of procs you are writing, then I doubt this is the best way to do it. I would be more inclined to write one stored procedure with one SELECT statement that joins 3 larger sets together (perhaps in temp tables) on the common value from a fourth set.

select *

from QueryFromSP1

outer join (QueryFromSP2) as QueryFromSP2
on QueryFromSP1.key = QueryFromSP2.key

...

The queries could be temp tables, or function calls, depending on the need, but a cursor like you have suggested will probably be a dog in performance (and not one of those really fast dogs either. Think hound dog on a hot Mississippi morning dogs.)

Friday, March 23, 2012

HELP! restore database - left in loading state? PLEASE HELP!

Hi all-
I actually don't work in SQL Server administration but I am trying to restore a database. I am a developer. I deleted all the rows from one of the tables in a database and I need to get that particular table back. The people that actually do the restor
e for me tell me that the RESTORE part has completed, but now the database says "(loading)" and stays this way indefinitely! They are trying to restore the database to a temporary location on another server, so that we can then just take the ONE table th
at I need back and import it back over. No one seems to have any idea how to move beyond this "loading" state and access the tables. Does this sound familiar to anyone? Please help - this is production data!!!!!! Thanks so much!!!
Try:
restore database MyDB with recovery
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"KMZ_state" <KMZ_state@.discussions.microsoft.com> wrote in message
news:A9DCF94E-276C-4D74-BB22-D55FCD672461@.microsoft.com...
Hi all-
I actually don't work in SQL Server administration but I am trying to
restore a database. I am a developer. I deleted all the rows from one of
the tables in a database and I need to get that particular table back. The
people that actually do the restore for me tell me that the RESTORE part has
completed, but now the database says "(loading)" and stays this way
indefinitely! They are trying to restore the database to a temporary
location on another server, so that we can then just take the ONE table that
I need back and import it back over. No one seems to have any idea how to
move beyond this "loading" state and access the tables. Does this sound
familiar to anyone? Please help - this is production data!!!!!! Thanks
so much!!!
|||Try:
restore database MyDB with recovery
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"KMZ_state" <KMZ_state@.discussions.microsoft.com> wrote in message
news:A9DCF94E-276C-4D74-BB22-D55FCD672461@.microsoft.com...
Hi all-
I actually don't work in SQL Server administration but I am trying to
restore a database. I am a developer. I deleted all the rows from one of
the tables in a database and I need to get that particular table back. The
people that actually do the restore for me tell me that the RESTORE part has
completed, but now the database says "(loading)" and stays this way
indefinitely! They are trying to restore the database to a temporary
location on another server, so that we can then just take the ONE table that
I need back and import it back over. No one seems to have any idea how to
move beyond this "loading" state and access the tables. Does this sound
familiar to anyone? Please help - this is production data!!!!!! Thanks
so much!!!
sql

Monday, March 19, 2012

Help! How to insert multiple rows into Database??

I keep getting this error but it will only insert the 1st row into my database table

The variable name '@.CustId' has already been declared. Variable names must be unique within a query batch or stored procedure.

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim drow As GridViewRow

For Each drow In GridView1.Rows

Dim textBoxText As String = CType(drow.FindControl("Label2"), Label).Text

SqlDataSource2.InsertParameters.Add("CustId", TypeCode.String, Profile.UserName)

SqlDataSource2.InsertParameters.Add("OrderDate", TypeCode.DateTime, DateTime.Now.ToString)

SqlDataSource2.InsertParameters.Add("Total", TypeCode.Double, TotalUnitPrice)

SqlDataSource2.InsertParameters.Add("Quantity", TypeCode.Int32, textBoxText)

SqlDataSource2.Insert()

Next

Response.Redirect("checkout.aspx")

End Sub

since you are operating in a loop, you should clear your parameters collection on each pass through

Dim drowAs GridViewRowFor Each drowIn GridView1.RowsDim textBoxTextAs String =CType(drow.FindControl("Label2"), Label).Text SqlDataSource2.InsertParameters.Clear()'<-- Clear the params first SqlDataSource2.InsertParameters.Add("CustId", TypeCode.String, Profile.UserName) SqlDataSource2.InsertParameters.Add("OrderDate", TypeCode.DateTime, DateTime.Now.ToString) SqlDataSource2.InsertParameters.Add("Total", TypeCode.Double, TotalUnitPrice) SqlDataSource2.InsertParameters.Add("Quantity", TypeCode.Int32, textBoxText) SqlDataSource2.Insert()Next
|||

Try this after your insert:

SqlDataSources2.InsertParameters.Clear();

There is another way to do this. Declare your parameters first, then assign the InsertParameters' default values for each InsertParameter after the insert.

SqlDataSource2.InsertParameters("Parameter1").DefaultValue=valueofParameter1

...

|||Omg .. thanks a lot ! It works... Haha ...

Wednesday, March 7, 2012

Help! - Error in moving data from AS400

I have a process that simply copies data from a table on an AS400 to SQL Server. This process executes fine until it gets to around 44 million rows copied out of 48 million rows in the source table. At this point, the process exits with the following error messages:

The attempt to send a row to SQL Server failed with error code 0x80004005.

The ProcessInput method on component "SQL Server Destination" (40) failed with error code 0xC02020C7.
The identified component returned an error from the ProcessInput method.
The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.

Thread "WorkThread0" has exited with error code 0xC02020C7.

The attempt to add a row to the Data Flow task buffer failed with error code 0xC0047020.

Thread "SourceThread0" has exited with error code 0xC0047038.

I am using the Microsoft OLEDB Provider for DB2 to access the AS400 and have tried the Table/View and SQL Command access modes with the same result.

Any help will be Greatly Appreciated!

-Mark Redman.

Hi Mark

The error was from your SQL Server Destination rather than from the DB2 source.

Which connection you have at your destination and which provider?

Thanks
Wenyang|||Hi Mark

This is not directly related to your problem, but I am also trying to use the MS OLE DB Provider for DB2 for connecting to an AS400, but I cannot make it work... How are your parameters setup? Could you perhaps post a screenshot?|||I am using the SQL Native Provider as the destination. It is a SQL Server 2005 Release Version server.|||The Parameters I have filled in are:

APPC Mode Name: QPCSUPP
APPC Security Type: Program
Defer Prepare: False
Derive Parameters False
Host CCSID 37
Network Address BKL400 <this would be different for you>
Network Port 446
Network Transport Library TCPIP
Package Collection QSYS2
PC Code Page 1252
Data Source bkl400
Initial Catalog bkl400
I hope this helps!|||The error was from your destination provider. Seems to me it's not related to the source you used in your package. I'm not sure whether you are using MS OLEDB for ODBC, if that's the case, search online using the error code 0x80004005 may bring you to some helpful web sites.

Thanks
Wenyang|||

The destination provider I am using is the Native OLEDB/SQL Native Client (SQLNCLI).

Friday, February 24, 2012

Help with writing sql statement

I need some help writing a query. I have a text file that will be imported on a weekly basis, with 1000+ rows and 5 columns. This i need to import into table tblECR which i have added 2 of my own columns.

The problem is the text file will arrive with current data and new data. The current data may or may not have changed (dates, status etc). How do i go about importing the new data and updating the existing data with the new fields, without deleting the data in the 2 columns i've added. I'm using vs 2005 with a sql 2005 express database.

This is the code i'm using to import the data currently. Clicking the button more than once will obviously just import all the data into the database again.

Private Sub CustomerDataToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomerDataToolStripMenuItem.Click

'Clear the dataset

dsimport.Clear()

'Set the file variables

Dim strFileName As String

Dim strFilePath As String

Dim sSlash As Single

'Open the file dialog and select the text file to open

Try

With OpenFileDialog1

'Set the initial dialog options

.Title = "Import Customer data file"

.InitialDirectory = "P:\Ian\"

.FileName = ""

.Filter = "File (*.csv)|*.csv|All files (*.*)|*.*"

If OpenFileDialog1.ShowDialog() <> Windows.Forms.DialogResult.Cancel Then

Else

MessageBox.Show("No file was selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information)

Exit Sub

End If

'Strip the filename into its seperate portions

sSlash = InStrRev(.FileName, "\")

strFilePath = Mid(.FileName, 1, CInt(sSlash))

strFileName = Mid(.FileName, CInt(sSlash + 1), Len(.FileName))

End With

'Set the connection properties to read the text file

Dim strConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & strFilePath & ";" & "Extended Properties=""text;HDR=NO;FMT=Delimited"""

Dim conn As New OleDb.OleDbConnection(strConnectionString)

'Open connection with the database.

conn.Open()

'Create new OleDbCommand to return data from the text file

Dim objCmdSelect As New OleDb.OleDbCommand("SELECT * FROM [" & strFileName & "]", conn)

' Create new OleDbDataAdapter that is used to build a DataSet based on the preceding SQL SELECT statement

Dim objAdapter1 As New OleDb.OleDbDataAdapter

'Pass the Select command to the adapter

objAdapter1.SelectCommand = objCmdSelect

'Fill the DataSet with the information from the file

objAdapter1.Fill(dsimport, "Import")

objAdapter1.AcceptChangesDuringFill = False

'Clean up objects

conn.Close()

Catch ex As Exception

MsgBox(ex.Message).ToString()

Exit Sub

End Try

'Now import the data into the table

Dim sqlcn As New SqlConnection(ConnString)

Dim sqlcmd_ECR As New SqlCommand

Dim dr As DataRow

Try

sqlcn.Open()

'Setup the sql command to enter data into the ECR table

sqlcmd_ECR.Connection = sqlcn

sqlcmd_ECR.CommandText = "Insert into tblECR_Test(ECR_No,Aims_No,ECR_Type) Values(@.a,@.b,@.c)"

'Setup the sql parameters to enter data into the ECR table

sqlcmd_ECR.Parameters.Add("@.a", SqlDbType.Int)

sqlcmd_ECR.Parameters.Add("@.b", SqlDbType.Int)

sqlcmd_ECR.Parameters.Add("@.c", SqlDbType.VarChar, 255)

Try

For Each dr In dsimport.Tables(0).Rows

sqlcmd_ECR.Parameters("@.a").Value = dr(0)

sqlcmd_ECR.Parameters("@.b").Value = dr(1)

sqlcmd_ECR.Parameters("@.c").Value = dr(2).ToString()

sqlcmd_ECR.ExecuteNonQuery()

Next

Catch ex1 As SqlException

MsgBox(ex1.Message).ToString()

Exit Sub

End Try

MessageBox.Show("The text file was successfully imported.", "Customer data import", MessageBoxButtons.OK, MessageBoxIcon.Information)

Catch ex3 As Exception

MsgBox(ex3.Message).ToString()

End Try

sqlcn.Close()

End Sub

ExecuteNonQuery returns an integer that tells you how many rows were affected by the query, so you could run an update first (trying to update the record assuming it is already there) and then if the rows affected is 0 instead of 1, run the insert.