|
Hi guys,
Heres my problem, i created a stored procedure that takes a person's ID number as a parameter
and says if the id number is Valid or Invalid. So basically after it has done the necessary calculation, i just state at the end to get an output:
If @CalcID = @ControlDigit
Select 'Valid'
Else
Select 'IN-Valid'
Now, in another sql script, i have a select statement to get all members, display the fields i need where where the members id's are invalid, basically like this :
Select Name,Email,Phone
from Members
Where ValidateIDNum Members.IDNum = 'IN-Valid'
ValidateIDNum is the procedure i stated above.
but kept getting errors, complaining about incorrect syntax near ValidateIDNum
Is this the right way, to do this type of work, also i tried the same work around using functions but still to no avail.
please help.
Thank You In Advance.
-- modified at 8:53 Wednesday 13th September, 2006
|
|
|
|
|
Why not do it without the function
Select Name,Email,Phone
from Members
Where Members.IDNum = @ControlDigit
only two letters away from being an asset
|
|
|
|
|
well i dont think that will work,
because, the control digit is calculated from the ID Number by a twenty step process, and this calculation should equal the last digit of the ID Number.
I want to break this process up, since we will probably be using it alot.
Im just trying to change the whole thing without procedures and with a cursor loop.
|
|
|
|
|
Use a function, and put parenthesis around the parameters you are sending in.
Select Name,Email,Phone
from Members
Where ValidateIDNum<code><big>(</big></code>Members.IDNum<code><big>)</big></code> = 'IN-Valid'
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
SQL Trigger not working on update statement
hi
i am having a table with 3 columns (a,b,c).
i have written a trigger for INSERT / UPDATE as c=a+b
this is working fine as long as i enter/update each row by row manually.
but, when i use any update statement for a set of rows, the trigger is firing only for the last row.
can anyone please help?
Thanks
|
|
|
|
|
Do you know that if an Update statement affects multiple rows, the trigger fires only once, and in the trigger you have to select from the virtual tables INSERTED and DELETED to get the copies of the affected rows.
|
|
|
|
|
hi
i am having a table with 3 columns (a,b,c).
i have written a trigger for INSERT / UPDATE as c=a+b
this is working fine as long as i enter/update each row by row manually.
but, when i use any update statement for a set of rows, the trigger is firing only for the last row.
can anyone please help?
Thanks
|
|
|
|
|
If the 'c' column is only a calculation of a+b, why not just use ([a] + [b]) as a formula?
Anyway, you could also use INSTEAD OF triggers:
CREATE TRIGGER InsteadUpdateTrigger on tblTable
INSTEAD OF UPDATE
AS
BEGIN
UPDATE tblTable
SET a=i.a,b=i.b,c=i.a+i.b
FROM INSERTED i
WHERE tblTable.IDField = i.IDField
END
CREATE TRIGGER InsteadInsertTrigger on tblTable
INSTEAD OF INSERT
AS
BEGIN
INSERT INTO tblTable
SELECT a,b,a+b
FROM INSERTED
END
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Is there a reason for not using a VIEW on this table? The table would have columns a and b. The view would have columns a, b, and c where c is defined as (a+b).
Chris Meech
I am Canadian. [heard in a local bar]
Nobody likes jerks. [espeir]
The zen of the soapbox is hard to attain...[Jörgen Sigvardsson]
I wish I could remember what it was like to only have a short term memory.[David Kentley]
|
|
|
|
|
Or, just give the c field a formula of ([a] + [b]):
CREATE TABLE [tblTable] (
[IDField] [int] IDENTITY (1, 1) NOT NULL ,
[a] [int] NULL ,
[b] [int] NULL ,
<code>[c] AS ([a] + [b]) </code>,
CONSTRAINT [PK_tblIDField] PRIMARY KEY CLUSTERED
(
[IDField]
) ON [PRIMARY]
) ON [PRIMARY]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Here i am developing a application which require to fetch Time from database . But i am getting 00:00:00 AM as a time everytime. We are using MySql database.
Code fragment is....
========================================================
_variant_t vtValue;
vtValue = RsSession->Fields->GetItem("StartTime")->GetValue();
COleDateTime d( vtValue );
sprintf( name, "%02d:%02d:%02d",d.GetHour(),d.GetMinute(),d.GetSecond() );
========================================================
in "name" i am getting "00:00:00" ..everytime.. All the other values i am retrieving from ResultSetPtr are OK.
Can any one tell me what is to be done ther ....
Thanks in advance
Prafulla Vedante
e-mail : prafulla_v@asianitg.com
|
|
|
|
|
What is the data type of the field "StartTime"?
|
|
|
|
|
Data type of the field "StartTime" is "time"
Prafulla Vedante
|
|
|
|
|
I have been programming an application with VC++ 2005 and SQL Server 2005. I have converted an old 16-bit database for 32-bit managed code and SQL server and the application seems to be good. Now I want to deploy the application to another server for testing.
I have installed XP SP2, Windows Installer 3.1, Net framework 2.0 and SQL Server 2005 express to the test server. I have transferred the application with WI 3.1 and the program works well in the test server till the first SQL command. I have made a back up of the database and restored in the test server. In the test server I can log in the database with Server Management studio and I can read the data there correctly. I have enabled both named pipes and TCP/IP for the database in the test server. With Surface Area Configuration I have enabled Local and Remote Connections Using both TCP/IP and named pipes. I only need Windows authentication at this time.
After all this when I come to the first SQL command in the application on the test server I receive the error message:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server).
My connection string to the database is:
'connection->ConnectionString = "Persist Security Info=False; Integrated Security =SSPI;"
"Data Source=TESTSERVER; Initial Catalog=TESTDATABASE;";'
When I use "Data Source=DevelopmentServer", the application works well on the development server.
Can't understand what is still wrong. Can anyone possibly have an answer?
|
|
|
|
|
Finally found the solution as there was an error in the command string. In SQLExpress server the data source must be presented in format SERVER\SQLExpress. When this is part of the above C++ command string it must have the format
"Data Source=TESTSERVER\\SQLExpress; Initial Catalog=TESTDATABASE;";
although the backslash is within quotation marks.
|
|
|
|
|
If suppose we have to add a row in a table, using insert and there is a primary key(PKID) which is auto incremented.
After executing the SP how will we know that what being the value of that key, i.e. to retrieve it from the SP itself,
i had heard that there is a particular command for that
Can someone help me plz................
|
|
|
|
|
If you want to get the PKID(auto incremented) then you can use @@IDENTITY for that. This will give you the PKID of just inserted recored.
Best Regards,
Apurva Kaushal
|
|
|
|
|
I didn't get your reply and what I soppose that you fine mine question unclear
So let me clarify it
I am asking that Suppose there is an SP that store some information Inserted by user and it generate automatically an ID (identity element) for that particular information.
Now after calling this SP in some of the function I want the PKID that is assigned to recent information, How can I retrive this PKID ??
|
|
|
|
|
Do a select statement using this:
SELECT IDENT_CURRENT('table_name')
This will return the last inserted PK in the table
or
SELECT @@IDENTITY
Try sql help on these two functions and see how they work exacly
|
|
|
|
|
Oh fine and Thanku vary much Mr. Devil and Mr. Apurva
|
|
|
|
|
Hello every one!
Well I have a question here about the self joined table. Well I know how it works theoretically but I’m working on it for the first time in SQL Server 2000. I’m trying to build a data entry form for it and now I’m a bit confused that how do we manage the Foreign Key of that table. I don’t know if I’m putting this question in the rt manner. How do we make the forms over a self joined table. Plz answer that having the auto-increment PK in mind. I’m working in .net 2.0 C# Windows Forms.
Thanks in advance…
Rocky
|
|
|
|
|
I'm not an expert in this but since you've had no other replies, here is my opinion...
Just create your form as if the underlying table didn't have a self join.
It's purpose is to relate two fields in the same table and is really only to make data retrieval (queries, SP's etc) easier and more efficient.
Steve
|
|
|
|
|
hello every one,
well I'm working on my first professional DB project, and this database has got inventory managmnt, billing, ledgers, and employee mgt modules. So for now I've made the main page very simple. Its got a tab control (I'm working in .net 2.0 C#) with two tabs 1 for forms and the other for reports with each tab having the links to the forms. But it doesnt look very elegant.
right now I'm just short of ideas of how to make the mian page and what sort of format I should give to the forms. can u plz suggest a few good looking and easily navigatable designs. or is there any website that gives u a few samples of good looking UIs
thanks in advance...
Rocky
|
|
|
|
|
Hi
Is it good practice to return multiple result set from single stored procedure when all result set will be used to populate a single page.
e.g.
CREATE PROCEDURE WHYNOT
AS
BEGIN
SELECT col1,col2 from table1
SELECT col3,col4 from table2
SELECT col5,col6 from table3
PS: 1) These are simple statements, but i will have joins on each query....
Please advice and guide.
Amit
|
|
|
|
|
It isn't necessarily a bad idea however depending on the amount of data returned it could be. Making fewer trips to the database can be a benefit but if the results returned are very large it may be better to break up the requests.
only two letters away from being an asset
|
|
|
|