Showing posts with label assistance. Show all posts
Showing posts with label assistance. Show all posts

Friday, March 30, 2012

HELP!!! Creating Nested Data in Repeated Region Problem

Hi All, Would appreciate some assistance with the attached, I'm using some fairly complicated recordsets (ASP VBScript) for a property search website, I have a page where a user selects search by County this in turn takes them to a page which lists all the towns in the county and number of live properties in each, I'm using 4 recordsets for this - 3 of which list the towns (townsA2I, townsJ2R & townsS2Z) the 4th is a Property Count, examples of the recordsets are below (using townsAtoI and LiveProperties -

TownsA2I

<%
Dim TownA2I
Dim TownA2I_numRows

Set TownA2I = Server.CreateObject("ADODB.Recordset")
TownA2I.ActiveConnection = MM_recruta2_STRING
TownA2I.Source = "SELECT towncountyID, Town, County FROM dbo.easytolettowncounty WHERE Town LIKE 'A%' AND County = '" + Replace(TownA2I__MMColParam, "'", "''") + "' OR Town LIKE 'B%' AND County = '" + Replace(TownA2I__MMColParam1, "'", "''") + "' OR Town LIKE 'C%' AND County = '" + Replace(TownA2I__MMColParam2, "'", "''") + "' OR Town LIKE 'D%' AND County = '" + Replace(TownA2I__MMColParam3, "'", "''") + "' OR Town LIKE 'E%' AND County = '" + Replace(TownA2I__MMColParam4, "'", "''") + "' OR Town LIKE 'F%' AND County = '" + Replace(TownA2I__MMColParam5, "'", "''") + "' OR Town LIKE 'G%' AND County = '" + Replace(TownA2I__MMColParam6, "'", "''") + "' OR Town LIKE 'H%' AND County = '" + Replace(TownA2I__MMColParam7, "'", "''") + "' OR Town LIKE 'I%' AND County = '" + Replace(TownA2I__MMColParam8, "'", "''") + "' ORDER BY Town ASC"
TownA2I.CursorType = 0
TownA2I.CursorLocation = 2
TownA2I.LockType = 1
TownA2I.Open()

TownA2I_numRows = 0
%>

LiveProperties

<%
Dim LiveProperties
Dim LiveProperties_numRows

Sub sLivePropertyCount(vLocation)
vCount=0

Set LiveProperties = Server.CreateObject("ADODB.Recordset")
LiveProperties.ActiveConnection = MM_recruta2_STRING
LiveProperties.Source = "SELECT COUNT(PropertyID) As NumberofProperties, propertylive, propertylocation FROM dbo.easytoletproperty WHERE propertylive = 'y' AND propertylocation = " & vLocation & " GROUP BY propertylocation, propertylive"
LiveProperties.CursorType = 0
LiveProperties.CursorLocation = 2
LiveProperties.LockType = 1
LiveProperties.Open()

vCount=(LiveProperties("NumberofProperties"))
Response.write(vCount)

LiveProperties.Close()
Set LiveProperties = Nothing
end sub

LiveProperties_numRows = 0
%>

I've tried following the tutorial here http://www.webthang.co.uk/tuts/tuts_dmx/rob9/rob9.asp but when i review the page i get the following error -

"Microsoft OLE DB Provider for SQL Server error '80040e14'

Invalid column name 'Barnet'.

/PropertiesbyTown1.asp, line 338 "

Where line 338"

Where line 338 is the "LiveProperties.Open()" of the above recordset, when i try to view bindings on this recordset Dreamweaver gives me the following errors -

"Column 'dbo.easytoletproperty.propertylive' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.

Column 'dbo.easytoletproperty.propertylocation' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause."

I would appreciate any assistance -

Try adding propertylocation to the GROUP BY clause as indicated by the error message.

Wednesday, March 21, 2012

Help! Need assistance!

I have a table with following columns:
Tutorial Number
Lesson Number
Order Number
where each tutorial has many lessons and there is a order number for
each lesson within that tutorial.
In the UI, once the user re-sorts the lessons in any manner which they
like, I am to store the new order as is the order in the datagrid.
How can I do that?
what should the Stored Procedure do?
thanks in advance,On 30 Sep 2005 14:15:08 -0700, nashak@.hotmail.com wrote:

>I have a table with following columns:
>Tutorial Number
>Lesson Number
>Order Number
>where each tutorial has many lessons and there is a order number for
>each lesson within that tutorial.
>In the UI, once the user re-sorts the lessons in any manner which they
>like, I am to store the new order as is the order in the datagrid.
>How can I do that?
>what should the Stored Procedure do?
>thanks in advance,
Hi nashak,
Homework assignment for school?
I think you need one stored procedure, to move one lesson to a new
location. Input parameters would be the tutorial number, the lesson to
be moved and the new location (either "before" or "after" another
lessen; in both cases you'll need a special value for "end of list" or
"start of list").
Draw some examples, think about possible cases (move forward - move
backward - "move", but new location = old location - etc), and work out
how in each of these cases the assigned Order Numbers should change.
Then translate those rules into SQL, hand in the assignment to your
teacher, and hope he or she doesn't read this group.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Hugo,
Wish it were just as simple as homework assigment.. :-)
The actual columns are different. I thought of these just as a sample.
What I am trying to do is as follows:
My table stores the Tutorial, lessons in that tutorial and the order of
the lessons.
The datagrid in my UI has been bound to the dataset that I created with
the above table. This grid has buttons to move the lessons up or
down(and thereby changing the order) as well as a checkbox to delete
the lesson from the tutorial. I need to first delete all the deleted
lessons and then capture the order of lessons and store this new order
in the "OrderOfLesson" column.
One way I think is to put a client side script that would change order
at every button click and store that order as well as change status of
rows that have been deleted. Then just update the database by calling
update() of the datatable. Is there some example code of the above that
i could look at?|||Some more stuff:
The table stores Order of lessons. However the Datagrid does not
display the order number. Is there anyway for the dataset to contain
order number column but for the Datagrid to not display that column?
In the above case, I could then at the Save event
(1) Go thru dataset and re-order all the rows and then call Update() of
dataset to update the rows in the database.
Does this sound possible?|||On 1 Oct 2005 08:06:35 -0700, nashak@.hotmail.com wrote:

>Hugo,
>Wish it were just as simple as homework assigment.. :-)
>The actual columns are different. I thought of these just as a sample.
>What I am trying to do is as follows:
>My table stores the Tutorial, lessons in that tutorial and the order of
>the lessons.
>The datagrid in my UI has been bound to the dataset that I created with
>the above table. This grid has buttons to move the lessons up or
>down(and thereby changing the order) as well as a checkbox to delete
>the lesson from the tutorial. I need to first delete all the deleted
>lessons and then capture the order of lessons and store this new order
>in the "OrderOfLesson" column.
>One way I think is to put a client side script that would change order
>at every button click and store that order as well as change status of
>rows that have been deleted. Then just update the database by calling
>update() of the datatable. Is there some example code of the above that
>i could look at?
Hi nashak,
Not a homework assignment, then. Okay. Sorry for being suspicious.
Anyway, that doesn't change the rest of my answer: you should have a
stored procedure that you can call to move a lesson around in the order.
The body of the stored procedure would probably consist of some IF's to
determine which of the various cases applies (giving one order a higher
place in the list, giving one order a lower place in the list, maybe
some more as well), and one UPDATE statement for each of the cases.
Here's the outline of an UPDATE statement that will move the lesson that
held the 6th place to the 3rd place (and simulteneously move the lessons
that were at 3rd, 4th and 5th place one place down):
UPDATE Lessons
SET Place = CASE WHEN Place = 6 THEN 3 ELSE Place + 1 END
WHERE Place BETWEEN 3 AND 6
AND other criteria
The real procedure would use variables, of course :-)
If you need more help, then please provide some more information about
your tables (as CREATE TABLE statements) and sample data (as INSERT
statements) that I can use to build and test the procedure. For tips on
how to assemble this information: www.aspfaq.com/5006.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Hello,
I did think of that. However the concern that I have is that this SP is
called everytime the user moves a lesson up and down. i.e if lesson
goes up I do order-- for that and order++ for the previous one. Too
many db calls.
Instead, I would like to see if I can let the user do whatever he wants
and then try to store the complete data from grid/dataset with a new
order starting from the first row.
Thanks,|||A general SP for re-ordering a sequential column has been posted
before.|||On 1 Oct 2005 15:13:03 -0700, nashak@.hotmail.com wrote:

>Hello,
>I did think of that. However the concern that I have is that this SP is
>called everytime the user moves a lesson up and down. i.e if lesson
>goes up I do order-- for that and order++ for the previous one. Too
>many db calls.
>Instead, I would like to see if I can let the user do whatever he wants
>and then try to store the complete data from grid/dataset with a new
>order starting from the first row.
>Thanks,
Hi nashak,
The advantage of using "too many db calls" is that changes are persisted
directly. No data loss if the client crashes. Of course, that's a down
side as well, as you'll either have to settle for no "abort all changes"
button, or use a long running transaction that will cause blocking and
hurt concurrency.
If you prefer using less db calls, build an app roughly like this:
- Get lessons and their relative positions from DB; store into array.
- Allow user to change order. Note changes in array.
- If user decides to abort changes, do nothing.
- If user decides to accept changes, call stored procedure that updates
order column for all lessons in one UPDATE statement. Do check if
someone else made changes in the meantime (you can use a rowversion
column for this - google "optimistic locking" for more details).
- If stored procedure reports changes by other users, go back to step 1
(or allow user to choose to override changes by other, or ...)
Getting the changed information back to the stored procedure requires an
array parameter. Unfortunately, there is no such thing in SQL Server.
See http://www.sommarskog.se/arrays-in-sql.html for some alternatives.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)sql

Friday, February 24, 2012

Help with writing a Stored Procedure

Hi there,
I would be really grateful with some assistance with this, i am 100% new to
SQL & Stored Procedures. I'm building an ASP web application, i need to be
able to update two fields in two related tables & could really do with some
assistance. The tables are tbCompany and tbemployee. tbemployee is related t
o
tbCompany through a field in tbemployee named CompanyId (int). The fields
that i need to update are CompanySuspendedAccount in tbCompany
EmpCompAccoutSuspended in tbemployee. Needless to say there could be multipl
e
records in tbemployee that are related to the one record in tbCompany.
Ideally i will need to write two stored procedures, the first that updates
all records to yes and the second to no.
I would be really grateful for some assitance with this - Many thanks
GarethAssuming some thing that you didn=B4t posted a SP could bve something
like this for you:
CREATE PROCEDURE UPDSuspendCode
(
@.CompanyId INT,
@.Suspend BIT
)
AS
BEGIN
DECLARE @.Error INT
BEGIN TRANSACTION
UPDATE tbCompany
SET CompanySuspendedAccount =3D @.Suspend
Where CompanyId =3D @.CompanyId
SET @.ERROR =3D @.@.Error
UPDATE tbemployee
SET EmpCompAccoutSuspended =3D @.Suspend
Where CompanyId =3D @.CompanyId
SET @.ERROR =3D @.Error + @.@.Error
IF @.Error > 0
BEGIN
RAISERROR('And Error has occured during updating the suspend
status',16,1)
ROLLBACK
END
ELSE
COMMIT
END
HTH, Jens Suessmeyer.|||Thanks Jene, it looks good to me, presumably here i am setting the value to
Suspend? So i could use @.yes BIT for the suspending of the accounts and @.no
BIT to unsuspend. Both the fields CompanySuspendedAccount &
EmpCompAccoutSuspended are nvarchar so presumably it would need to be as
above unless i change the database? Thanks for your help
Gareth
"Jens" wrote:

> Assuming some thing that you didn′t posted a SP could bve something
> like this for you:
> CREATE PROCEDURE UPDSuspendCode
> (
> @.CompanyId INT,
> @.Suspend BIT
> )
> AS
> BEGIN
> DECLARE @.Error INT
> BEGIN TRANSACTION
>
> UPDATE tbCompany
> SET CompanySuspendedAccount = @.Suspend
> Where CompanyId = @.CompanyId
> SET @.ERROR = @.@.Error
>
> UPDATE tbemployee
> SET EmpCompAccoutSuspended = @.Suspend
> Where CompanyId = @.CompanyId
> SET @.ERROR = @.Error + @.@.Error
> IF @.Error > 0
> BEGIN
> RAISERROR('And Error has occured during updating the suspend
> status',16,1)
> ROLLBACK
> END
> ELSE
> COMMIT
> END
>
> HTH, Jens Suessmeyer.
>|||"@.yes BIT " Thats what my @.Suspend is for, you don=B4t need a @.Suspende
AND @.Unsuspense because the twi BITs can never evaluate to true (can be
either switch on AND off, right ).
You don=B4t have to change the database because BIT a Integer data type
with the constraint of being 1, 0, or NULL, so implicit conversion will
be used.
DECLARE @.Suspense BIT
DECLARE @.SomeColumn NVARCHAR(200)
SET @.Suspense =3D 1
SET @.SomeColumn =3D @.Suspense
Print @.SomeColumn
HTH, jens Suessmeyer.

Sunday, February 19, 2012

Help with update query linking 3 tables

I am looking for some assistance with an update query that needs to link 3
tables:

This query ran and reported over 230,000 records affected but did not change
the field I wanted changed, not sure what it did.
I did notice that the "name" in "GM_NAMES.name" was colored blue in Query
Analyzer. Is it bad to name a column "name"?

UPDATE ABSENCES
set CustomerContactID = cicntp.cnt_id
from absences, cicntp
where (SELECT cicntp.cnt_l_name
FROM cicntp INNER JOIN
gm_names ON cicntp.cnt_l_name = GM_NAMES.name INNER JOIN
Absences ON cicntp.cnt_id = Absences.CustomerContactID)

Next I tried this query which is still running after 75 minutes (on a
laptop)

update absences
set CustomerContactID = cicntp.cnt_id
from absences, cicntp, gm_names
where gm_names.name= cicntp.cnt_l_name

As you can see, the 3 tables are ABSENCES, CICNTP and GM_NAMES.
Absences.CustomerContactID is what I need updated, when finished it should
match CICNTP.cnt_id
GM_NAMES is a temp table and matches records in CICNTP.cnt_l_name

Can some of you school this newbie on the best way to do this?
Thanks a bunch!On Fri, 15 Apr 2005 19:54:56 GMT, rdraider wrote:

>I am looking for some assistance with an update query that needs to link 3
>tables:
>This query ran and reported over 230,000 records affected but did not change
>the field I wanted changed, not sure what it did.
>I did notice that the "name" in "GM_NAMES.name" was colored blue in Query
>Analyzer. Is it bad to name a column "name"?
>UPDATE ABSENCES
>set CustomerContactID = cicntp.cnt_id
>from absences, cicntp
>where (SELECT cicntp.cnt_l_name
> FROM cicntp INNER JOIN
> gm_names ON cicntp.cnt_l_name = GM_NAMES.name INNER JOIN
> Absences ON cicntp.cnt_id = Absences.CustomerContactID)

Hi rdraider,

I guess that you made a copy & paste error, since this query can never
have reported over 230,000 rows affected - it can only report "Incorrect
syntax near ')'".

>Next I tried this query which is still running after 75 minutes (on a
>laptop)
>update absences
>set CustomerContactID = cicntp.cnt_id
>from absences, cicntp, gm_names
>where gm_names.name= cicntp.cnt_l_name

Depending on the size of the tables, it'll probably run a whole lot
longer - and it likely won't result in the change you wish. Since you
didn't specify anything to link absences to either of the other tables,
this query will effectively:

1. Join cicnt and gm_names on the name column, as specified in the WHERE
clause; then
2. Update EACH row in absences with the value of EACH row in the result
of the join above. If that join yields a million rows, then each row in
absences will be updated a million times. And in the end, the cnt_id
value from whatever row happens to be processed last will end up being
in CustomerContactID for ALL absences!

>As you can see, the 3 tables are ABSENCES, CICNTP and GM_NAMES.
>Absences.CustomerContactID is what I need updated, when finished it should
>match CICNTP.cnt_id
>GM_NAMES is a temp table and matches records in CICNTP.cnt_l_name
>Can some of you school this newbie on the best way to do this?
>Thanks a bunch!

Neither this narrative, nor any of the queries you posted does a very
good job at explaining what you need to get done. A much better way to
ask help in newsgroups is to post the table structure (as CREATE TABLE
statements), some rows of sample data (as INSERT statements) and the
expected output. More on this can be found at www.aspfaq.com/5006.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||1) Learn the Standard SQL UPDATE syntax, so you will not get Cartesian
explosions problems that will destroy your data integrity.

2) Avoid temp tables in favor of derived tables that the optimizer can
use.

3) Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are. Sample data is also a good idea, along with clear
specifications.

4) Here is a wild guess. I would replace GM_names with a derived
table.

UPDATE Absenses
SET customer_contact_id
= (SELECT C1.cnt_id
FROM Cicntp AS C1, GM_names AS G1
WHERE C1.cnt_l_name = G1.name
AND C1.cnt_id = Absences.customer_contact_id)
WHERE EXISTS
(SELECT *
FROM Cicntp AS C1, GM_names AS G1
WHERE C1.cnt_l_name = G1.name
AND C1.cnt_id = Absences.customer_contact_id);

If the subquery expression returns no rows, you will get a NULL; If it
retursn more than one row, you will get a cardinality violation.|||On 15 Apr 2005 15:21:03 -0700, --CELKO-- wrote:

>4) Here is a wild guess. I would replace GM_names with a derived
>table.
>UPDATE Absenses
> SET customer_contact_id
> = (SELECT C1.cnt_id
> FROM Cicntp AS C1, GM_names AS G1
> WHERE C1.cnt_l_name = G1.name
> AND C1.cnt_id = Absences.customer_contact_id)
> WHERE EXISTS
> (SELECT *
> FROM Cicntp AS C1, GM_names AS G1
> WHERE C1.cnt_l_name = G1.name
> AND C1.cnt_id = Absences.customer_contact_id);

Hi Joe,

I was starting to post the exact same solution, but then I saw that this
version makes no sense at all - look at the way the subqueries are
joined to the table to be updated: the effect will be that
customer_contact_id will only be changed if it already has the correct
value. In other words: this UPDATE statement might affect some rows, but
it definitely won't change any data!

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||Yes. But this is what he wrote when both of us (who are pretty good
SQL guys) trie to understand it. It would be nice to have some DDL and
clear specs instead of bad code ...