|
The examples that come with the help for SQL Server show how to use a cursor. You can use a cursor on any select, across any number of tables. As you step through it, you an insert into a new table from each row.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I have to statements inside the StoredProcedure. If in the first satement occured Error I want exit from the StoredProcedure. For this Scenario, How to write StoredProcedure
Mohan Balal
|
|
|
|
|
You can use try-catch block to catch the exceptions..
See THIS
PS. you are asking basic questions...try and search for them on google before asking. Take an initiative yourself and we will help you in it, but if you want us to take an initiative for you YOU MISS-READ THE IDEA OF CODE PROJECT .
Mubashir
Software Architect
Storan Technologies Inc, USA
Every job is a self portrait of the person who did it.
|
|
|
|
|
Thanks for your Reply and kind suggestions
Mohan balal
|
|
|
|
|
select count(*) from Emp
Select count(empid) from Emp
what is the different between above two sql statements
Mohan Balal
|
|
|
|
|
Count(*)
returns the number of items in a group, including NULL values
Count(fieldName)
returns the number of items in a group, excluding NULL values
Hope it helps
Mubashir
Software Architect
Storan Technologies Inc, USA
Every job is a self portrait of the person who did it.
|
|
|
|
|
Thanks a lots
Mohan balal
|
|
|
|
|
what is the difference between
SELECT group_name
FROM groups,users_groups
WHERE users_groups.user_id=x and groups.group_id=x
VS
SELECT group_name
FROM groups
INNER JOIN users_groups
ON users_groups.user_id = groups.group_id
|
|
|
|
|
In the first statement you leave it up to the sql query parser to decide how to join the tables. In the second case you are telling the query parser how you want the two tables joined. With only two tables it may not be a big deal other then the first example is slopy. Once you start to have several tables you are trying to join to your tables may not join together they way you want them to. I would sugest always use the second method. It make your code clear as far as what you are trying to do.
Hope that helps.
Ben
|
|
|
|
|
Hello all,
I'm looking for what you would consider the best book on SQL Server 2005 Stored Procedures.
Looking for suggestions, what would you recommend?
Thanks in advance,
Silvio
http://www.silvio.us
-- modified at 13:44 Sunday 15th April, 2007
|
|
|
|
|
Dear all,
I would like to insert data entered into datagridview(dgv1) into the two fields (with name "code" and "qty") of a database table "stock"
Below is the code. The problem is that the codes run smoothly without error but the data entered into the DGV1 is not inserted into the database:
1. Here are the code at form load. I populate the DGV (with name dgv1) with the existing data of the table 'stock':
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim tbl As New DataTable
tbl.Columns.Add("s_code", GetType(String))
tbl.Columns.Add("S_name", GetType(String))
Dim constr As String = "data source=DADDY-desktop;initial catalog=Fund_System;Integrated Security=True"
Dim sqlstr As String = "select * from stock"
dgv1.DataSource = bs
da = New SqlDataAdapter(sqlstr, constr)
Dim table As New DataTable()
da.Fill(table)
tbl = table
bs.DataSource = tbl
End Sub
2. Here are the codes initiated by a click of a button which was hit after the user has entered code into the datagridview dgv1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sqlcon As String = "data source=DADDY-desktop;initial catalog=Fund_System;Integrated Security=True"
Dim con As New SqlConnection(sqlcon)
con.Open()
da.InsertCommand = New SqlCommand("insert into stock VALUES (@code, @qty)", con)
Dim pc As SqlParameterCollection
pc = da.InsertCommand.Parameters
pc.Add("@code", SqlDbType.Char, 10, "code")
pc.Add("@qty", SqlDbType.Char, 10, "qty")
Dim tbl As DataTable = New DataTable("cus_table")
da.Fill(tbl)
dgv1.DataSource = tbl
da.Update(tbl)
con.Close()
End Sub
bindingsource bs and DataAdapter da are declare outside of 1 and 2 above, under the Public Class Form1 heading:
Private bs As New BindingSource()
Private da As New SqlDataAdapter()
Can anybody point out what's wrong with the code?
Thank you very much.
|
|
|
|
|
Hellow to all ..
i am trying to Import Data into my sql server 2000 , the data is Access database when i creat new database, i go to tables and go into the wizard i follow the steps and when i finsh i don't see any tables ...
but if i import data to a database name Master , i can see the tables ..
anyidea ?
thxx for anyhelp ..
|
|
|
|
|
During the Wizard Import and Export process when prompted to identify a destination did you select New and then name it?
Learning is not a spectator sport. - D. Blocher
|
|
|
|
|
thxx my friend i was doing things fine , but i should refresh the list in order to see the new tables ..
thxx
|
|
|
|
|
hi,i'm new here,it's my first time to ask a question..
I'm trying to join 2 tables together using sql query as following:
insert into table1
select * from
table2
but if there's a record in table2 which disobey referential integrity constraints,the query would be terminated,and the rest were failed to insert.
I have also tried to use cursor to fetch record one by one,but it's too trouble to judge every column type.
I'm looking for some efficient solutions..
oh,I'm so sorry for my poor english!
Thanks a lot in advance,
ChongHui.Ren
-- modified at 8:07 Saturday 14th April, 2007
|
|
|
|
|
I am assuming that the problem you have is that some of the records in table2 already exist in table1. So your query would need to be:
insert into table1
select t2.* from
table2 t2
left join table1 t1 on t2.key = t1.key
where t1.key is null
I am assuming you have a column in both tables called key, most likely you call the column something else. The select statement will only give you the records in table2 that are not already in table1
Hope that helps.
Ben
|
|
|
|
|
thanks for your help
select t2.* from
table2 t2
left join table1 t1 on t2.key = t1.key
where t1.key is null
but i exeute select statement above,the query result is always null,why?
|
|
|
|
|
If the query results are always null that would mean that the rows that are in table1 are already in table2.
You can check this by doing this
Select count(*) from table1
select count(*) from table2 t2
join table1 t1 on t2.key = t1.key
The counts should match if everything that is in table1 is in table2
Hope that helps.
Ben
|
|
|
|
|
Imagin that i made a sql database an its application now i want to install my file into target computer how cam i do that .
|
|
|
|
|
hi ...
i wan to export data in sql server 2005 with wizard but take follow error !!!!!
"Only part of a ReadProcessMemory or WriteProcessMemory request was completed (System)"
is any query (in sql server) that i can export data ?
thanks
|
|
|
|
|
Sounds more like a hardware fault than anything wrong with SQL Server. If you google for the error message you'll see that it crops up a lot on hardware driver support forums.
|
|
|
|
|
hi
can i bind a field in comboBox. i filled a datatable in dataset with data from database and tried to bind a column with comboBox but no data appeared. i set the combobox dataSource to the datatable and set the dataMember to the columnName.
isearched for that and i found the solution is do make a dataView. it works fine but i wanna anther solution if u can help me.
anther thing,
i tried to use the select command of the datatable to filter the data and bind the returned array to combobox but its not work. i set the dataSource to the arrayName and the dataMember to columnName like this
dim dr() as dataRow = ds.tables(0).select("where id > " & id)
comDate.dataSource = dr
comDate.DataMember = "BatchDate"
the table has these columns (ID,BatchDate,....) but the dates doesnt appear
|
|
|
|
|
Mdallal84 wrote: dataMember to the columnName.
Isn't it the DisplayMember you need to set to show data ? The DataMember sets the data associated with the current selection, not the one shown.
I also believey you need to call the DataBind() method.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
you can't bind to a datarow collection.
Consider making a dataview, and then setting the datasource to the dataview.
Also, you need to set the .DisplayMember and the .DataMember.
|
|
|
|
|
Hi in sqlserver stored procedure i am doing some calculations...,
See the below procedure:
select a.empid,b.empName,c.Whrs,c.srg,case when srg=0 then @Outsunday else @Insunday end as days,c.Bassalary,
(Bassalary/(days*Whrs)) as onehour,
sum(AppWHours) as TWhrs,Sum(AppOtHours) as TOThrs
from tblMonthHourDetails a,tblemployeemaster b,tblsalarydetails c where
a.empid=b.empid and a.empid=c.empid and
b.projectid=@projectid and datepart(mm,[SDate])=@months and datepart(yy,[SDate])=@Years group by a.empid,b.empName,c.Whrs,c.srg,c.Bassalary
In that above procedure using case condition i am getting one column "days" like...,
That days value i want to use to calculate for onehour column,
if i give there days(highlighted in above procedure) value its telling error msg like invalid column days like...,
but i want to use that value there how to use...,
Plz any one solve my probs.....,
Magi
|
|
|
|