|
Hello friends,
which is the better way to use transaction?
From Database
or from Application?
|
|
|
|
|
There is no answer to this, it depends on many factors I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi,
I need some help with the database design for storing an expression tree. It should basically store a whole expression.
I'd want to query out data (in one or more result sets as necessary) so that I can finally evaluate it somehow in my front-end application. Just kind of need a table(s) structure to store and represent the relationship.
The expressions I plan to store in the database will be mostly logical expressions. Meaning they'd evaluate to a true or false mostly.
Here is a diagrammatic representation of what I want (as a result set(s)).modified on Thursday, March 4, 2010 8:31 AM
|
|
|
|
|
Hi,
I often use trees and what you essentially needs is the ID and Parent ID
for example:
ID | ParentID | Name
1 | 0 | A
2 | 1 | AA
3 | 1 | AB
4 | 0 | B
5 | 4 | BA
6 | 4 | BB
looks like:
[]
|
-A
--AA
--AB
-B
--BA
--BB
and so on...
... I hope you mean this
|
|
|
|
|
I am using VB.Net 2008 and ADO.Net to do a Batch Update to our Oracle database.
The updates are working, but there is a trigger on the table before the row is updated to enforce a member's termination termination date.
So if I was trying to set the termination date (via the batch update) to 31-Jan-2010 but the member had a claim that was processed on 2-Feb-2010 the trigger would force the termination date to be 2-Feb-2010.
However, the trigger is NOT executing when the batch update runs?
|
|
|
|
|
I would guess that triggers are disabled for batch updates then, probably as a database default. This is a sensible idea, you do NOT want triggers firing in volume and you should be managing your data not relying on a trigger. I hate the bloody things, always causing trouble, hiding under the hood and causing issues bah! Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Good idea. I'm not a DBA so do you know for sure if there is an admin option that disable a trigger for batch updates?
|
|
|
|
|
MB_KSU wrote: do you know
No idea, especially on OracleNever underestimate the power of human stupidity
RAH
|
|
|
|
|
Can any one please tell me how to call a stored procedure from case statement. Thanks In Advance
|
|
|
|
|
A Case statement in SQL is an embedded part of a Select statement so you can't call a stored procedure in the middle, only a function. However I guess you mean something more like the following:
If @Test = 1
Execute [Procedure1];
Else If @Test = 2
Execute [Procedure2];
Else If @Test = 3
Execute [Procedure3];
Else
Execute [Procedure4];
|
|
|
|
|
you can also use case when for this.
|
|
|
|
|
You are still not going to be able to exec another proc from withing the case statement! Case and Exec() do not go together! Never underestimate the power of human stupidity
RAH
|
|
|
|
|
No you can't.
To quote the Micosoft documentation[^]:
The CASE expression cannot be used to control the flow of execution of Transact-SQL statements, statement blocks, user-defined functions, and stored procedures. For a list of control-of-flow methods, see Control-of-Flow Language (Transact-SQL)[^].
The question was regarding calling stored procedures and that is clearly not possible from within a case statement.
|
|
|
|
|
Table 1 (UNITS)
ScanID ScanCount OrderID SerialNo ScanStatus ProductionNo
1981 1294 2 147639NZ301774 SHIPPED 10007627289
There are 1300 SerialNo's for ProductionNo That will end with status 'SHIPPED'
Table 2 (Unit_Logs)
LogID SerialNo ProductionNo Old_Status New_Status
1 147639NZ301774 10007627289 PACKED SHIPPED
There will be 1300 records with status changes from PACKED to SHIPPED
Needed RESULT:
ProductionNo PACKED SHIPPED
10007627289 1300 1300
This is what I have tried:
SELECT UNITS.ProductionNo, COUNT(UNITS.SerialNo) AS SHIPPED,
COUNT(UNIT_Logs.SerialNo) AS PACKED
FROM UNITS JOIN UNIT_Logs
ON UNITS.ProductionNo = UNIT_Logs.ProductionNo
GROUP BY UNITS.ProductionNo, UNITS.ScanStatus, UNIT_Logs.Old_Status
HAVING (UNITS.ScanStatus = 'SHIPPED') AND (UNIT_Logs.Old_Status = 'PACKED')
I added 1 log entry to the table, but the query returns nothing.
Think might need sub query, but not sure where to go from here.
|
|
|
|
|
HAVING is only meant to be used with aggregate functions.
Try something similar to this:
SELECT UNITS.ProductionNo, COUNT(UNITS.SerialNo) AS SHIPPED,
COUNT(UNIT_Logs.SerialNo) AS PACKED
FROM UNITS JOIN UNIT_Logs
ON UNITS.ProductionNo = UNIT_Logs.ProductionNo
WHERE (UNITS.ScanStatus = 'SHIPPED') AND (UNIT_Logs.Old_Status = 'PACKED')
GROUP BY UNITS.ProductionNo, UNITS.ScanStatus, UNIT_Logs.Old_Status
<edit>fixed layout</edit>"When did ignorance become a point of view" - Dilbert
modified on Wednesday, March 3, 2010 3:54 AM
|
|
|
|
|
SELECT UNITS.ProductionNo,
COUNT(UNITS.SerialNo) AS SHIPPED,
COUNT(UNIT_Logs.SerialNo) AS PACKED
FROM UNITS
JOIN UNIT_Logs
ON UNITS.ProductionNo = UNIT_Logs.ProductionNo
WHERE (UNITS.ScanStatus = 'SHIPPED') AND (UNIT_Logs.Old_Status = 'PACKED')
GROUP BY UNITS.ProductionNo
|
|
|
|
|
Hi,
Thanks for the replies.
This query only seems to make a 1 to 1 join.
So if there is only one log entry it returns both SHIPPED and PACKED as 1 instead of 1294.
ProductionNo SHIPPED PACKED
10007627289 1 1
if i remove:
WHERE (UNITS.ScanStatus = 'SHIPPED') AND (UNIT_Logs.Old_Status = 'PACKED')
ProductionNo SHIPPED PACKED
10007627289 1294 1294
I tried this mess. Will try a few more options with this.
SELECT UNITS.ProductionNo, COUNT(UNITS.SerialNo) AS SHIPPED
FROM UNITS
WHERE UNITS.Scanstatus='SHIPPED' AND
(SELECT COUNT(UNIT_Logs.SerialNo) AS PACKED FROM UNIT_Logs WHERE UNIT_Logs.Old_Status='PACKED')
GROUP BY UNITS.ProductionNo
|
|
|
|
|
Try this one.
SELECT u.ProductionNo,
u.SHIPPED,
l.PACKED
FROM
(
SELECT ProductionNo,
COUNT(SerialNo) AS SHIPPED
FROM UNITS
WHERE ScanStatus = 'SHIPPED'
GROUP BY ProductionNo
) u
LEFT OUTER JOIN
(
SELECT ProductionNo,
COUNT(SerialNo) AS PACKED
FROM UNIT_Logs
WHERE Old_Status = 'PACKED'
GROUP BY ProductionNo
) l
ON l.ProductionNo = u.ProductionNo
[Fixed typo]modified on Wednesday, March 3, 2010 7:56 AM
|
|
|
|
|
Wow. did not even know you could do this.
I get this error though:
Msg 156, Level 15, State 1, Line 8
Incorrect syntax near the keyword 'FROM'.
Msg 102, Level 15, State 1, Line 19
Incorrect syntax near 'l'.
I am going to break it down into components to make sure the parts work and then try and connect it back together again.
Thanks
|
|
|
|
|
Sorry found the problem. , before the FROM in the first bracket.
It works perfectly. Thanks for the help.
|
|
|
|
|
|
I am creating a dynamic pivot-table with web - sql-server 2008
When the pivot-table is created i want to rename columnname.
I am execute a stored procedure, sp_rename..... from the web-page.
Web-page - select variablesnames
Web-page - variablesname --> short columnname
SQl-server - create pivot table (dynamic sql, short columnnames - 4000 char limit)
Web-page/Sql-server - rename short columnnames to variablesnames
The problem is the permission to execute sp_rename .
How/where can I adjust permission for the the "webuser" in sql-server ?
Thanks in advance
Clas
|
|
|
|
|
I am assuming that you need this table only for display on your form, in which case why don't you rename the columns in the UI! Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have 2 tables in my data base..
1. User_Group table
2. Function_Group table
Example:
Function_Group table :
Groupid Applicationid Functionid
LCUser1 LCDocMgmt LC01
LCUser2 LCDocMgmt LC02
LCUser1 LCDocMgmt LC03
LCUser3 LCDocMgmt LC04
LCUser3 LCDocMgmt LC05
LCUser2 LCDocMgmt LC06
LCUser2 LCDocMgmt LC08
LCUser1 LCDocMgmt LC09
User_Group table:
Userid Groupid
900410 LCUser1
900846 LCUser1
900411 LCUser3
Now i use the following query to retrieve the Groupid for a particular Userid :
Select ug.groupid from User_Group ug, Function_Group fg where fg.ApplicationID='LCDocMgmt' and fg.GroupID = ug.GroupID and ug.UserID='900846'
The result that i get on executing the above query is:
groupid
LCUser1
LCUser1
LCUser1
Actually i Dont require repetition of records. If there is 2 distinct records i just want the 2 distinct records without repetition.. can any one plz help me..
Thanx in advance....
Regards,
Tash
|
|
|
|
|
<<tash18>> wrote: distinct records
You answered your own question.
Select DISTINCT ug.groupid from User_Group ug, Function_Group fg where fg.ApplicationID='LCDocMgmt' and fg.GroupID = ug.GroupID and ug.UserID='900846'
|
|
|
|