Click here to Skip to main content
15,909,656 members
Home / Discussions / Database
   

Database

 
AnswerRe: another query Pin
Goutam Patra23-Jul-10 22:58
professionalGoutam Patra23-Jul-10 22:58 
GeneralRe: another query Pin
reza assar24-Jul-10 1:03
reza assar24-Jul-10 1:03 
Questionquery Pin
reza assar23-Jul-10 21:32
reza assar23-Jul-10 21:32 
AnswerRe: query Pin
Goutam Patra23-Jul-10 22:57
professionalGoutam Patra23-Jul-10 22:57 
AnswerRe: query Pin
Mycroft Holmes23-Jul-10 23:05
professionalMycroft Holmes23-Jul-10 23:05 
QuestionMessage Removed Pin
23-Jul-10 21:06
prachidalwadi23-Jul-10 21:06 
AnswerRe: How to optimize the query with more than one left outer join Pin
CitrusTech23-Jul-10 21:14
CitrusTech23-Jul-10 21:14 
Questionsql problem Pin
bapu288923-Jul-10 20:40
bapu288923-Jul-10 20:40 
hello all

i am working on one of my assignment about sql win app. with stored procedure.and there is two different tables with ralation to PlotID so it's working fine. now only problem is this application must have functionality to add multiple customer names with related land plot.

At the moment i can add one name and one land plot

i mean if i add some details about land plot and name of customer then it works fine but now i need to create functionality to add multiple customer name with same land plot bueause one land plot may have multiple owners.

this is my insert sp

so one of my friend said you can use multiple parameters to add multiple names but what if i need to add 3 or 4 names

so this is what i have done according to my friend and this is also working fine.

ALTER PROCEDURE dbo.InsertNew
(
	@FirstName nvarchar(25),
	@LastName nvarchar(25),
	@FirstName2 nvarchar(25),
	@LastName2 nvarchar(25),
	@Village nvarchar(25),
	@District nvarchar(25)
)
AS
	SET NOCOUNT ON;
	DECLARE @PlotID int
	
	INSERT INTO PlotDetails (Village,District)

VALUES (@Village, @District)
	
	SELECT @PlotID=SCOPE_IDENTITY()

	
INSERT INTO CustomerDetails ([FirstName], [LastName],[PlotID]) 

(SELECT @FirstName, @LastName, @PlotID)
UNION ALL
(SELECT @FirstName2, @LastName2, @PlotID)

	RETURN



and this is vb for insert record


Private Sub InsertNew()
       Try
           Comm = New SqlClient.SqlCommand("InsertNew", LetsGo.AndGetConnection)
           Comm.CommandType = CommandType.StoredProcedure
           Comm.CommandText = "InsertNew"

           Comm.Parameters.Add("@Village", SqlDbType.NVarChar).Value = ComboBox1.SelectedItem.ToString
           Comm.Parameters.Add("@District", SqlDbType.NVarChar).Value = ComboBox2.SelectedItem.ToString

           Comm.Parameters.Add("@FirstName", SqlDbType.NVarChar).Value = TextBox1.Text
           Comm.Parameters.Add("@LastName", SqlDbType.NVarChar).Value = TextBox2.Text


           Comm.Parameters.Add("@FirstName2", SqlDbType.NVarChar).Value = FirstName2.Text
           Comm.Parameters.Add("@LastName2", SqlDbType.NVarChar).Value = LastName2.Text

           Comm.ExecuteNonQuery()
           Conn.Close()
           MsgBox("Item Saved")

       Catch ex As Exception
           MsgBox(ex.Message)
       End Try


   End Sub



so is there any other way to do this i mean loop in sql?

waiting for your kind help

thanks
AnswerRe: sql problem Pin
Goutam Patra23-Jul-10 21:31
professionalGoutam Patra23-Jul-10 21:31 
QuestionRe: sql problem Pin
bapu288923-Jul-10 23:33
bapu288923-Jul-10 23:33 
AnswerRe: sql problem Pin
Goutam Patra23-Jul-10 23:56
professionalGoutam Patra23-Jul-10 23:56 
QuestionReverse of * Pin
Ray Cassick23-Jul-10 7:18
Ray Cassick23-Jul-10 7:18 
AnswerRe: Reverse of * Pin
Yusuf23-Jul-10 8:54
Yusuf23-Jul-10 8:54 
GeneralRe: Reverse of * Pin
Ray Cassick23-Jul-10 10:08
Ray Cassick23-Jul-10 10:08 
GeneralRe: Reverse of * Pin
Mycroft Holmes23-Jul-10 13:37
professionalMycroft Holmes23-Jul-10 13:37 
GeneralRe: Reverse of * Pin
Ray Cassick23-Jul-10 13:57
Ray Cassick23-Jul-10 13:57 
AnswerRe: Reverse of * Pin
Eddy Vluggen23-Jul-10 9:17
professionalEddy Vluggen23-Jul-10 9:17 
GeneralRe: Reverse of * Pin
Ray Cassick23-Jul-10 10:11
Ray Cassick23-Jul-10 10:11 
AnswerRe: Reverse of * Pin
Mycroft Holmes23-Jul-10 13:41
professionalMycroft Holmes23-Jul-10 13:41 
QuestionCannot test the registered server in SQL Server 2008, neither start, pause or stop Pin
Kujtim Hyseni23-Jul-10 6:01
Kujtim Hyseni23-Jul-10 6:01 
Questionproblem getting data in a group Pin
Dhyanga23-Jul-10 2:54
Dhyanga23-Jul-10 2:54 
AnswerRe: problem getting data in a group Pin
Corporal Agarn23-Jul-10 5:47
professionalCorporal Agarn23-Jul-10 5:47 
AnswerRe: problem getting data in a group Pin
Mycroft Holmes23-Jul-10 13:45
professionalMycroft Holmes23-Jul-10 13:45 
AnswerRe: problem getting data in a group Pin
CitrusTech23-Jul-10 21:11
CitrusTech23-Jul-10 21:11 
QuestionTable Optimization Problem - SQL Server Pin
Jacobus0123-Jul-10 2:36
Jacobus0123-Jul-10 2:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.