HI
I have 2 table in data base
1-Estate_p table
Id
|
Name
|
Date
|
Behcode
|
Code
|
1
|
Sara
|
2012/11/14
|
1111
|
25643
|
2
|
Jack
|
2012/10/12
|
2222
|
32156
|
and ADvertisment Table
Id
|
Name
|
Date
|
Behcode
|
Code
|
days
|
1
|
Sara
|
2012/11/14
|
1111
|
|
|
|
|
|
|
|
|
and I have 2 text box and 1 imgbutton
it text box I enter code and days that when I click on imgbutton if in Estate_p was the code that I enter in Text box It insert infromation from Estate_p tabel to Advertisment table
this is SP
ALTER procedure [dbo].[insertAD]
@day int
,@behcode nvarchar(10)
,@code varchar(20)
as
BEGIN
SET NOCOUNT ON;
DECLARE @Result INT
SET @Result = 1
IF EXISTS(SELECT behcode FROM Estate_p WHERE Code=@code )
BEGIN
INSERT INTO advertisment(behcode,[date], Name,[days])
SELECT behcode,[date],name ,@day
FROM Estate_p
WHERE behcode=@behcode and Code=@code
END
ELSE
BEGIN
SET @Result = 0
END
SELECT @Result
END
I mean I.e user with behcode=1111 just can insert 4 item from Estate_p to advertisment table if she insert morethan 4 item it show error
HOw I can do it?
thanks
you can refer to below thread
http://www.aspforums.net/Threads/132009/insert-data-from-one-Table-into-other-Table-if-data-does-not-exists-in-SQL-Server/?s=2&p=2#Replies