|
Using a check constraint you can do the following:
<br />
CREATE TABLE myChkTable (IsStatusUpdate BIT, NewDocStatus VARCHAR(25))<br />
go<br />
<br />
ALTER TABLE myChkTable ADD CONSTRAINT chkTblConstraint CHECK (<br />
(IsStatusUpdate = 1 AND NewDocStatus IS NOT NULL) OR IsStatusUpdate = 0<br />
)<br />
go<br />
<br />
--the first three will succeed<br />
INSERT INTO myChkTable VALUES (0, null)<br />
INSERT INTO myChkTable VALUES (1, 'status')<br />
INSERT INTO myChkTable VALUES (0, 'not update')<br />
<br />
--this will fail<br />
INSERT INTO myChkTable VALUES (1, null)<br />
<br />
|
|
|
|
|
I don't mean to sound stupid.
But what does the term "MRD" stands for in SQL Server?
Does anybody know?
Thanks.
R
|
|
|
|
|
Hi,
For the life of me, I haven't been able to figure the following out and I hoping someone out there can offer some good advice.
I have an ASP page that lists a lot of manuals and their associated new features for that particular release.
For example:
Manual title New Feature
manual 1 new feature1
manual 1 new feature2
manual 1 new feature3
manual 2 new feature1
manual 3 new feature1
manual 3 new feature2
Rather than have the same manual listed consecutively with a different new feature association, I would like to list the results as such:
Manual title New Feature
manual 1 new feature1
new feature2
new feature3
manual 2 new feature1
manual 3 new feature1
new feature2
Is this possible using ASP and SQL?
Here's the stored procedure:
<code>CREATE PROCEDURE [docadmin1].[sp_view_nfprodrel]
@product nvarchar (250)
AS
SELECT distinct top 100 Percent doc_id, title, relnum, substring(dn,3,14) as DN, product, New_Feature FROM nf_prodrel_man WHERE product = @product order by Title
GO</code>
Here's the view being called from the stored procedure:
<code>CREATE VIEW dbo.nf_prodrel_man
AS
SELECT TOP 100 PERCENT dbo.Books.Title + ' ' + dbo.Books.Rel_Num AS title, dbo.PROD_REL.Product, dbo.DOC_RELATIONSHIP.Doc_ID,
dbo.New_Feature.NF_ID, SUBSTRING(dbo.New_Feature.New_Feature, PATINDEX('% %', dbo.New_Feature.New_Feature),
LEN(dbo.New_Feature.New_Feature)) AS New_Feature, dbo.Books.DN, dbo.New_Feature.Description, RIGHT(dbo.PROD_REL.Product, 3)
AS RELNUM
FROM dbo.PROD_REL INNER JOIN
dbo.NF_PROD_REL ON dbo.PROD_REL.Prod_Rel_ID = dbo.NF_PROD_REL.Prod_REL_ID INNER JOIN
dbo.New_Feature ON dbo.NF_PROD_REL.NF_ID = dbo.New_Feature.NF_ID INNER JOIN
dbo.DOC_RELATIONSHIP ON dbo.NF_PROD_REL.REL_ID = dbo.DOC_RELATIONSHIP.REL_ID INNER JOIN
dbo.Books ON dbo.DOC_RELATIONSHIP.Doc_ID = dbo.Books.Doc_ID
ORDER BY dbo.Books.Title + ' ' + dbo.Books.Rel_Num, dbo.PROD_REL.Product</code>
Thanks in advance!
Regards,
Jenn
|
|
|
|
|
It is possible to do this in SQL, but it is much easier to acheive in the ASP page (especially as it is a presentation thing). The structure would look a bit like:
lngOldBookId = -1
For Each objRec In arrBookList
Response.Write("<tr><td>")
If lngOldBookId <> objRec.BookId Then
Response.Write(objRec.Title)
lngOldBookId = objRec.BookId
Else
Response.Write(" ")
End If
'write other bits of result table.
Next So you only print a book title when it is different from the previous record.
Hope that helps.
Andy
|
|
|
|
|
Thanks Andy. I will give a try and let you know how I fare.
Have a great day,
Jenn
|
|
|
|
|
I normalized a table in a database project I'm working on so that instead of having something like this:
Table: entities
-----------------
ID NAME RELATED_ITEM_ID_1 RELATED_ITEM_ID_2 ..... RELATED_ITEM_ID_40
1 Entity 1 1 24 67
2 Entity 3 14 NULL 45
I now have something like these two tables:
Table: entities
-----------------
ID NAME
1 Entity 1
2 Entity 3
Table: entity_items
-----------------
ENTITY_ID RELATED_ITEM_ID
1 1
1 24
1 67
2 14
2 45
I want to return a table that has a summary of the entities table returning the top three entity_items so that it will come back looking like the original (non-normalized) entities table.
I am using a MySQL database, but any help with the basic concepts and SQL here would be appreciated. I'm sure this is a common problem people deal with, but I didn't even know the terminology to use to find an answer on the web.
Thanks.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
|
Thank you. That was helpful.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Hello!
I can't execue the following sql string because I am getting an error message. How can I increment the specific field in the table by one?
SQLSTR = "UPDATE setup SET TotalUser=TotalUser + 1 WHERE RecordNumber = 1"
Thanks
Journey
|
|
|
|
|
B Journey wrote: I can't execue the following sql string because I am getting an error message.
What is the error message?
|
|
|
|
|
SQLSTR = "UPDATE setup SET TotalUser=TotalUser + 1 WHERE RecordNumber = 1"
Call Initialize_Connection()
Call Execute_Statement(SQLSTR) ' the error occurs in this procedure
the procedure content is here:
Sub Execute_Statement(GetSQL)
Set ObjectRecord = Server.CreateObject ("ADODB.Recordset")
ObjectRecord.CursorLocation = adUseServer
ObjectRecord.CursorType = adOpenkeyset
ObjectRecord.LockType = adLockOptimistic
ObjectRecord.Open GetSQL, ObjectConnection,,, adCmdText 'error points this line
End Sub
Thanks
|
|
|
|
|
Okay - so at least we now know WHERE the error is. You still have not told us WHAT the error is.
What is the error message?
|
|
|
|
|
Sorry! Here is the error message. I have double checked all fields in the table nothing looks wrong. It is working on my local server but when I transfer it to server in Internet, I am getting this error message.
Microsoft JET Database Engine error '80040e10'
No value given for one or more required parameters.
/emlak/include/scripts.inc, line 138
I have included the procedure in my previous message where the error is pointing the line 138.
Thanks
|
|
|
|
|
That's a typical error when you have misspelled one of the column names (e.g. TotalUsers or RecordNumber)
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers! We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP Linkify!|Fold With Us!
|
|
|
|
|
Try using an ADODB.Command object instead of a recordset. You are performing an update.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
That update should work. I would guess that either you don't have rights to update the setup table. Or you need to better qualify the setup table. Perhaps there is a dbo.setup table and a username.setup table. It is always a good idea to qualify your table names. If it isn't that most likely it is a security thing, the user that is running the update doesn't have update rights on that table. If you provided the error message we might be able to pin point the issue.
Hope that helps.
Ben
|
|
|
|
|
Please refresh my rusty SQL skills. I have a DocMaster table with Status and StatusTime fields, and I have a DocUpdate table with UpdateTime and DocStatus fields. The DocUpdate table stores a history of all status updates for a document, and the DocStatus and StatusTime fields in the DocMaster table are redundant copies of the UpdateTime and DocStatus fields for the most recent DocUpdate record for a given document. How do I update the DocMaster table to correct the values in these fields?
|
|
|
|
|
Hi Brad
Normally you would use a trigger to keep the two tables synchronised. If the tables are currently out of sync then the following should fix the master table:
update DocMaster set
DocStatus = A.DocStatus,
UpdateTime = A.UpdateTime
from DocUpdate A
where A.DocId = DocMaster.DocId
and A.UpdateTime = (select max(UpdateTime) from DocUpdate
where DocUpdate.DocId = DocMaster.DocId) This assumes that the primary key on DocMaster is named "DocId", and that the "UpdateTime" is unique for each document (if you have an identity column on DocUpdate then you should use that instead).
Hope that helps.
Andy
|
|
|
|
|
That's perfect, thanks Andy. I do have triggers doing the normal sync work, but whenever I create redundant or derived fields like these I always start with an update procedure that makes everything all good again, if something goes wrong.
|
|
|
|
|
Hi friends
What is a clustered index? How many records can take clustered index in sql server?
what is a cursor?
what is a sql injuction?
thanks in advance
khan
|
|
|
|
|
imrankhanpathan wrote: What is a clustered index?
You will find the answer in SQL-Server's "Books Online". A table can only have one clustered index defined (unless told otherwise SQL-Server will use a clustered index for primary keys). There is no practical limit on the number of records that can be held in a clustered index.
imrankhanpathan wrote: what is a cursor?
Again the answer is in "Books Online".
imrankhanpathan wrote: what is a sql injuction?
You can find out about "SQL Injection" here[^]
|
|
|
|
|
I have a single query that selects a product id. Everytime is finds a product id it also selects several other queries to build up a row of statistics. Therefore my query retrieves rows as follows:
Product ID | Stat Number One | Stat Number Two | More Stats
125 | 76% | 45% |
What I want is a final overall score at the end of the query in a final column. Built on the fly from the other columns. How can I do this?
Eg
(StatNumberOne + Stat Number Two + Rest of Stat Columns / Amount of Columns) As Overall Score
I don't know how to reference these columns on the fly like this ??
|
|
|
|
|
one way doing this is using union
Eg.
SELECT prodid, no1, no2, 0 as overall from ......
union
SELECT prodid, 0 as no1, 0 as no2, (no1 + no2) / x as overall from ......
other way of doing is use procedure
|
|
|
|
|
I am trying to call a Oracle stored procedure using ADO in C++.
The store procedure has 12 input parameters, and 2 output
parameters with one of them being a Ref Cursor. I followed the
example in a post by Koushik Biswas on the subject
(http://www.codeproject.com/script/Articles/list_articles.asp?userid=811562).
But when I called
pRecordset = pCommand->Execute(NULL, NULL,
adCmdStoredProc | adCmdUnspecified );
I got an error message of "Unspecified error".
I don't have visibility to the stored procedure, but using describe
from sqlplus, I got the following:
SQL> describe myproc
Parameter Type Mode Default?
----------------------- ---------- ---- --------
P_1 VARCHAR2 IN
P_2 NUMBER IN
P_3 NUMBER IN
P_4 NUMBER IN
P_5 NUMBER IN
P_6 NUMBER IN
P_7 NUMBER IN
P_8 NUMBER IN
P_9 NUMBER IN
P_10 NUMBER IN
P_11 DATE IN
P_12 VARCHAR2 IN
P_OUT_ERROR_TXT VARCHAR2 OUT
P_OUT_CURSOR REF CURSOR OUT
Most of the parameters can be set to NULL.
Here is part of my code:
spCmdOracle->CommandType = adCmdStoredProc;
spCmdOracle->CommandText = "{CALL myproc(?,?,?,?,?,?,?,?,?,?,?,?,?)}";
_bstr_t strdata = "MYTEST";
_ParameterPtr p_1 = spCmdOracle->CreateParameter("@p_1",
adVarChar, adParamInput,
strdata.length(), strdata);
spCmdOracle->Parameters->Append(p_1);
_variant_t d((float)25);
_ParameterPtr p_2 = spCmdOracle->CreateParameter("@p_2",
adSingle, adParamInput,
sizeof(float), d);
spCmdOracle->Parameters->Append(p_2);
_variant_t a((float)40);
_ParameterPtr p_3 = spCmdOracle->CreateParameter("@p_3",
adSingle, adParamInput,
sizeof(float), a);
spCmdOracle->Parameters->Append(p_3);
_variant_t null_id;
_ParameterPtr p_4 = spCmdOracle->CreateParameter("@p_4",
adSingle, adParamInput,
sizeof(float), null_id);
spCmdOracle->Parameters->Append(p_4);
_ParameterPtr p_5 = spCmdOracle->CreateParameter("@p_5",
adSingle, adParamInput,
sizeof(float), null_id);
spCmdOracle->Parameters->Append(p_5);
_variant_t o((float)10000);
_ParameterPtr p_6 = spCmdOracle->CreateParameter("@p_6",
adSingle, adParamInput,
sizeof(float), o);
spCmdOracle->Parameters->Append(p_6);
_variant_t p((float)20000);
_ParameterPtr p_7 = spCmdOracle->CreateParameter("@p_7",
adSingle, adParamInput,
sizeof(float), p);
spCmdOracle->Parameters->Append(p_7);
_ParameterPtr p_8 = spCmdOracle->CreateParameter("@p_8",
adSingle, adParamInput,
sizeof(float), null_id);
spCmdOracle->Parameters->Append(p_8);
_ParameterPtr p_9 = spCmdOracle->CreateParameter("@p_9",
adSingle, adParamInput,
sizeof(float), null_id);
spCmdOracle->Parameters->Append(p_9);
_ParameterPtr p_10 = spCmdOracle->CreateParameter("@p_10",
adSingle, adParamInput,
sizeof(float), null_id);
spCmdOracle->Parameters->Append(p_10);
_ParameterPtr p_11 = spCmdOracle->CreateParameter("@p_11",
adSingle, adParamInput,
sizeof(float), null_id);
spCmdOracle->Parameters->Append(p_11);
_ParameterPtr p_12 = spCmdOracle->CreateParameter("@p_12",
adBSTR, adParamInput,
sizeof(float), null_id);
spCmdOracle->Parameters->Append(p_12);
char out_error[1000];
_ParameterPtr p_13 = spCmdOracle->CreateParameter("@P_OUT_ERROR_TXT",
adBSTR, adParamOutput,
sizeof(out_error), out_error);
spCmdOracle->Parameters->Append(p_out_error_txt);
spRsOracle = spCmdOracle->Execute(NULL, NULL, adCmdStoredProc | adCmdUnspecified );
The last line caused an exception with "Unspecified error".
If I change the setting of spCmdOracle->CommandText to use the stored procedure name
instead of the excape sequence, I got an error message PLS-00306:
Code meaning = IDispatch error #3092,
Description = ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'MYPROC'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
I am new on this subject and cannot find any help nearby. I would greatly appreciate any
here can give me some hint on what could be wrong.
Thanks.
|
|
|
|
|
hi there
i have 2 table with no relationship between them
and i need 2 extract from table1 the col1
and the phase of col1 in table2 col2
for example:
Table1
Col1
1000
1001
1002
=============================================
Table2
Col2
A1000A
bbb1000bcd
cdf1000frg
A1001a
bvc1001dcfe
=============================================
Result:
colRes count_in_table_2
1000 3
1001 2
1002 0
thanks in advance
roni vars
|
|
|
|
|