Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 21st, 2004, 06:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default Condition

how can develop good condition ?

when query run, it select empno and contract from table and do this.


<%
empno=Request.Form("empno")
acontract=Request.Form("acontract")

ssql="select empno,contractno from approvals where empno='" & empno & "' and contractno='" & acontract &"'"

set rs=cn.Execute(ssql)

contractno=rs("contractno")

if contractno=acontract then // problem is her, it display blank page

//do this insert records one table only


isql1="insert into assignments(empno,acontract,aposit,astrdate,aendda te,cshift) values ("
isql2="'" & empno & "',"

isql3="'" & acontract & "',"

isql4="'" & aposit & "',"

if IsDate(astrdate) then
    isql5="'" & astrdate & "',"
else
    isql5="NULL,"
end if

if IsDate(aenddate) then
    isql6="'" & aenddate & "',"
else
    isql6="NULL,"
end if

isql7="'" & cshift & "')"

sql=isql1+isql2+isql3+isql4+isql5+isql6+isql7

cn.Execute sql

if err.number=0 then
Response.Redirect("add_passign2.asp")
else
Response.Redirect("add_passign3.asp")
end if


if contractno<>acontract then // insert records both tables.

isql1="insert into assignments(empno,acontract,aposit,astrdate,aendda te,cshift) values ("
isql2="'" & empno & "',"

isql3="'" & acontract & "',"

isql4="'" & aposit & "',"

if IsDate(astrdate) then
    isql5="'" & astrdate & "',"
else
    isql5="NULL,"
end if

if IsDate(aenddate) then
    isql6="'" & aenddate & "',"
else
    isql6="NULL,"
end if

isql7="'" & cshift & "')"

isql8="insert into assignto (empno,aposit,astrdate,aenddate,cshift,acontract,c ontractno) values ("
isql9="'" & empno & "',"
isql10="'" & aposit & "',"

if IsDate(astrdate) then
    isql11="'" & astrdate & "',"
else
    isql11="NULL,"
end if


if IsDate(aenddate) then
    isql12="'" & aenddate & "',"
else
    isql12="NULL,"
end if


isql13="'" & cshift & "',"

isql14="'" & acontract & "',"

isql15="'" & contractno & "')"


sql=isql1+isql2+isql3+isql4+isql5+isql6+isql7+isql 8+isql9+isql10+isql11+isql12+isql13+isql14+isql15

cn.Execute sql

if err.number=0 then
Response.Redirect("add_passign2.asp")
else
Response.Redirect("add_passign3.asp")
end if

end if
end if
%>


when contractno=acontract it does not insert records ?

when contractno<>acontract it insert records.

how can develop good conditional logic that records could be
inserted more then one condition ?

Regards.

Mateen
 
Old April 22nd, 2004, 05:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I am not sure, what you are trying to do there.

As per your code, You are trying to get the submitted contractno and empno, using which you run a select query. When there are no records found for that contractno and empno, then it won't let you execute the first if part (where contractno=acontract) Which you are already doing in your select statement. I am little consufed of what you are trying to do. It would be better to help you out, if you could explain what your requirement is, than posting such lengthy code, by which indirectly finding out what you are trying to do, is tough.

Cheers!

-Vijay G
 
Old April 22nd, 2004, 05:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Also I would request you to post your question in the right group to get better and faster help, than guess and assumptions, also to save time mutually.

-Vijay G
 
Old April 25th, 2004, 06:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for response.

I am out of country now-a-days (one week leaves) As I will join the Office, I will post the details code, with details problem.

regards.

Mateen


Quote:
quote:Originally posted by happygv
 Also I would request you to post your question in the right group to get better and faster help, than guess and assumptions, also to save time mutually.

-Vijay G
 
Old May 4th, 2004, 06:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for response.

with the reference of previous post.
I simply want.

(1) if approvals contract = assign contract then
    insert above records only in one table ie assignments table

(2) if approvals table contractno is blank then
     insert records in only one table ie. assignments table.

(3) if approval contract <> assign contract then
     it should insert records in two tables. ie. assignments and assignto tables.

end if
end if
end if

where acontract1 means assign contract
           contractno means approved contract


I use two asp files and tables are connected with the sql server.
I use droplown list.

PROJASSIGN.ASP coding is

  <TR>
    <TD>Employee Name</TD>
    <TD><SELECT id=empno name=empno><OPTION selected value="">Select Employee</OPTION>
 <%
dim ssql
set cn=server.CreateObject("adodb.connection")
cn.ConnectionString="Provider=SQLOLEDB.1;Integrate d Security=SSPI;Persist Security Info=False;Initial Catalog=Admin;Data Source=AUHTRIPSVR2"
cn.Open

ssql="select empno,name from employees order by name"

set rs=cn.Execute(ssql)
do while rs.eof=false
Response.Write("<option value='" & rs("empno") & "'>")
Response.Write(rs("name") )
rs.movenext
loop
%>
    </SELECT></TD></TR>

<TR>
    <TD>Assign to Contract/Location</TD>
    <TD><SELECT id=acontract name=acontract><OPTION selected value="">Select Contract/Location</OPTION>
 <%
set cn=server.CreateObject("adodb.connection")
cn.ConnectionString="Provider=SQLOLEDB.1;Integrate d Security=SSPI;Persist Security Info=False;Initial Catalog=Admin;Data Source=AUHTRIPSVR2"
cn.Open

ssql="select distinct contractno,appsta from approvals where appsta='approved'"

set rs=cn.Execute(ssql)
do while rs.eof=false
Response.Write("<option value='" & rs("contractno") & "'>")
Response.Write(rs("contractno") )
rs.movenext
loop
%>
    </SELECT></TD></TR>
    <TR>
    <TD>Assign Position</TD>
    <TD><SELECT id=aposit name=aposit><OPTION selected value="">Select Assign Position</OPTION>
 <%
set cn=server.CreateObject("adodb.connection")
cn.ConnectionString="Provider=SQLOLEDB.1;Integrate d Security=SSPI;Persist Security Info=False;Initial Catalog=Admin;Data Source=AUHTRIPSVR2"
cn.Open

ssql="select distinct posit from employees order by posit"

set rs=cn.Execute(ssql)
do while rs.eof=false
Response.Write("<option value='" & rs("posit") & "'>")
Response.Write(rs("posit") )
rs.movenext
loop
%>
    </SELECT></TD></TR>

    <TR>
    <TD>Assign Start&nbsp;Date (m/d/y)</TD>
    <TD><INPUT id=firstinput name=firstinput><input type=button Value=Calendar name=button1 id=button1 title="Calendar" onClick="javascript:showCal('Calendar1')"></TD></TR>
  <TR>
    <TD>Assign End Date (m/d/y)</TD>
    <TD><INPUT id=secondinput name=secondinput><input type=button Value=Calendar name=button2 id=button2 title="Calendar" onClick="javascript:showCal('Calendar2')"></TD></TR>
  <TR>
    <TD>Contract Shift No</TD>
    <TD><INPUT id=cshift name=cshift></TD></TR>



When I select any one employee in the dropdown list and click save button, it move to ADD_PASSIGN.ASP page
it retrieve (check) the records from APPROVALS table,

(1) if approvals contract = assign contract then
    insert above records only in one table ie assignments table

(2) if approvals table contractno is blank then
     insert records in only one table ie. assignments table.

(3) if approval contract <> assign contract then
     it should insert records in two tables. ie. assignments and assignto tables.

-------------------------Second File-------------------------
ADD_PASSIGN.ASP coding is


<%
empno1=Request.Form("empno")
acontract1=Request.Form("acontract")
aposit1=Request.Form("aposit")
astrdate1=Request.Form("firstinput")
aenddate1=Request.Form("secondinput")
cshift1=Request.Form("cshift")

set cn=server.CreateObject("adodb.connection")
cn.ConnectionString="Provider=SQLOLEDB.1;Integrate d Security=SSPI;Persist Security Info=False;Initial Catalog=Admin;Data Source=AUHTRIPSVR2"
cn.Open

ssql="select empno,contractno from approvals where empno='"& empno1 & "' and contractno='"& acontract1 &"'"

set rs=cn.Execute(ssql)

do while rs.eof=false

contractno1=Response.Write(rs("contractno"))

loop

if Response.Write(rs("contractno"))=acontract1 then

isql1="insert into assignments (empno,aposit,astrdate,aenddate,cshift,acontract) values ("
isql2="'" & empno1 & "',"
isql3="'" & aposit1 & "',"

if IsDate(astrdate1) then
    isql4="'" & astrdate1 & "',"
else
    isql4="NULL,"
end if


if IsDate(aenddate1) then
    isql5="'" & aenddate1 & "',"
else
    isql5="NULL,"
end if


isql6="'" & cshift1 & "',"

isql7="'" & acontract1 & "')"


sql=isql1+isql2+isql3+isql4+isql5+isql6+isql7

cn.Execute sql

if err.number=0 then
Response.Redirect("add_passign2.asp")
else
Response.Redirect("add_passign3.asp")
end if


if Response.Write(rs("contractno"))="" then

isql1="insert into assignments (empno,aposit,astrdate,aenddate,cshift,acontract) values ("
isql2="'" & empno1 & "',"
isql3="'" & aposit1 & "',"

if IsDate(astrdate1) then
    isql4="'" & astrdate1 & "',"
else
    isql4="NULL,"
end if


if IsDate(aenddate1) then
    isql5="'" & aenddate1 & "',"
else
    isql5="NULL,"
end if


isql6="'" & cshift1 & "',"

isql7="'" & acontract1 & "')"


sql=isql1+isql2+isql3+isql4+isql5+isql6+isql7

cn.Execute sql

if err.number=0 then
Response.Redirect("add_passign2.asp")
else
Response.Redirect("add_passign3.asp")
end if


if Response.Write(rs("contractno"))<>acontract1 then

isql1="insert into assignments (empno,aposit,astrdate,aenddate,cshift,acontract) values ("
isql2="'" & empno1 & "',"
isql3="'" & aposit1 & "',"

if IsDate(astrdate1) then
    isql4="'" & astrdate1 & "',"
else
    isql4="NULL,"
end if


if IsDate(aenddate1) then
    isql5="'" & aenddate1 & "',"
else
    isql5="NULL,"
end if

isql6="'" & cshift1 & "',"

isql7="'" & acontract1 & "')"

isql8="insert into assignto (empno,aposit,astrdate,aenddate,cshift,acontract,c ontractno) values ("
isql9="'" & empno1 & "',"
isql10="'" & aposit1 & "',"

if IsDate(astrdate1) then
    isql11="'" & astrdate1 & "',"
else
    isql11="NULL,"
end if


if IsDate(aenddate1) then
    isql12="'" & aenddate1 & "',"
else
    isql12="NULL,"
end if


isql13="'" & cshift1 & "',"

isql14="'" & acontract1 & "',"

isql15="'" & contractno1 & "')"

sql=isql1+isql2+isql3+isql4+isql5+isql6+isql7+isql 8+isql9+isql10+isql11+isql12+isql13+isql14+isql15

cn.Execute sql

if err.number=0 then
Response.Redirect("add_passign2.asp")
else
Response.Redirect("add_passign3.asp")
end if


end if
end if
end if
%>


Thanks for your cooperation

Mateen







Quote:
quote:Originally posted by happygv
 I am not sure, what you are trying to do there.

As per your code, You are trying to get the submitted contractno and empno, using which you run a select query. When there are no records found for that contractno and empno, then it won't let you execute the first if part (where contractno=acontract) Which you are already doing in your select statement. I am little consufed of what you are trying to do. It would be better to help you out, if you could explain what your requirement is, than posting such lengthy code, by which indirectly finding out what you are trying to do, is tough.

Cheers!

-Vijay G
 
Old May 5th, 2004, 06:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

PROJASSIGN.ASP
Were you getting the list displayed? In nowhere I see you closing the <OPTION> tag with </OPTION> withing the WHILE LOOP...

Quote:
quote:
(1) if approvals contract = assign contract then
    insert above records only in one table ie assignments table

(2) if approvals table contractno is blank then
     insert records in only one table ie. assignments table.

(3) if approval contract <> assign contract then
     it should insert records in two tables. ie. assignments and assignto tables.
As in all cases whatever the condition is you are storing the record in Assigments table, you dont have to check on any condition for that. Only when you wanted to insert records in "Assignto" table, you check for the CONDITION " if approval contract <> assign contract then"

ADD_PASSIGN.ASP
Quote:
quote:
do while rs.eof=false
contractno1=Response.Write(rs("contractno"))
loop
What do you do in the above loop? I dont see anything being done there other than an INFINITE loop. No movement of RECORDSET pointer. You will never come out of it.

Hope that takes you on the right path after correcting the above said.

Cheers!

-Vijay G
 
Old May 6th, 2004, 03:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks.


Quote:
quote:Originally posted by happygv
 PROJASSIGN.ASP
Were you getting the list displayed? In nowhere I see you closing the <OPTION> tag with </OPTION> withing the WHILE LOOP...

Quote:
quote:
(1) if approvals contract = assign contract then
    insert above records only in one table ie assignments table

(2) if approvals table contractno is blank then
     insert records in only one table ie. assignments table.

(3) if approval contract <> assign contract then
     it should insert records in two tables. ie. assignments and assignto tables.
As in all cases whatever the condition is you are storing the record in Assigments table, you dont have to check on any condition for that. Only when you wanted to insert records in "Assignto" table, you check for the CONDITION " if approval contract <> assign contract then"

ADD_PASSIGN.ASP
Quote:
quote:
do while rs.eof=false
contractno1=Response.Write(rs("contractno"))
loop
What do you do in the above loop? I dont see anything being done there other than an INFINITE loop. No movement of RECORDSET pointer. You will never come out of it.

Hope that takes you on the right path after correcting the above said.

Cheers!

-Vijay G





Similar Threads
Thread Thread Starter Forum Replies Last Post
or condition kgoldvas XSLT 1 July 31st, 2007 03:44 AM
where condition...? mnr555 Crystal Reports 0 June 18th, 2006 05:32 PM
Please check my where condition mat41 SQL Language 4 May 26th, 2006 08:52 AM
if then else condition mateenmohd Classic ASP Basics 0 April 16th, 2005 07:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.