|
I'm wondering if someone could help me with the SQL I'd need to accomplish the following: I have a db with a number of text fields and what I want to do is have a search box in my program that will search all fields for the text entered. For example I have first_name, last_name, alias, etc. and let's say I enter "Jim" in the search field. I want to be able to search all the fields (first_name, last_name, etc) for that term. Is this possible? I'd also like to use the LIKE operator so the text doesn't have to be exact.
Thanks!
- Aaron
|
|
|
|
|
Maybe something like this:
Select * from table where first_name like '%searchString%' or last_name like '%searchString%' or ....
Or
Select * from table where first_name + last_name + .... like '%searchString%'
--
Don't take life seriously because you can't come out of it alive.
-Warren Miller
|
|
|
|
|
That seems to work quite well. Wondering if you could help with another question...how would I make the search string dynamic, as in I want to be able to pass in the value as a paramter...can I do this, if so what's the syntax?
Thanks very much for the help.
- Aaron
|
|
|
|
|
I did not get it. Could you explain a little more about what you want to do?
--
Don't take life seriously because you can't come out of it alive.
-Warren Miller
|
|
|
|
|
Sure. This is basically what my T-SQL looks like:
SELECT * FROM dbo.Books
WHERE title LIKE '%search%' OR author LIKE '%search%' What I want to do is be able to pass in "search" as a parameter. I'm not sure how to do this though because if I remove the quotes around the search sting and add the @ in front of it, I get a syntax error. I hope that's clearer.
Thanks again for the help.
- Aaron
|
|
|
|
|
Maybe something like this:
Declare @a varchar(50)<br />
<br />
SELECT * FROM dbo.Books<br />
WHERE title LIKE '%' + @a + '%' OR author LIKE '%' + @a + '%'
--
Don't take life seriously because you can't come out of it alive.
-Warren Miller
|
|
|
|
|
Hello! I have been using Datasets and DataAdapters by dragging and dropping on my form. Now I have created a public class and created a dataset by code and filled it wit a Dataadapter. Dataset contains one table "DEPARTMENT" with columns "D_ID" and "D_NAME". Dataset is filled and contains data but when in windows form i tried to bind a combobox to that table it creates problems.
1) dim ClassObj as new DSClass
2)CobmoBox1.datasource = ClassObj.Dataset1.Tables("DEPARTMENT")
3)CobmoBox1.DisplayMember = ?????????????????????????
4)CobmoBox1.DisplayMember = ?????????????????????????
Lines 3,4 creates problems, Please guide me
as900197
|
|
|
|
|
One should be DisplayMember (the column that you want displayed in your combo), the other should be ValueMember (the column that represents the data you want to store).
For example, if you have a table with columns ID and Description, you could set your DisplayMember to 'ID' and your ValueMember to 'Description'.
On your form, you will see the value in the Description displayed in your combo but you will actually store the corresponding ID when updating your DataSet.
CobmoBox1.DisplayMember = "ID"
CobmoBox1.ValueMember = "Description"
Steve
|
|
|
|
|
Thanks Steve!
It was so little mistake and i get so depressed....
Thank you
as900197
|
|
|
|
|
You are welcome.
Upon reading my answer again, I actually got the values the wrong way round!
You would normally have the DisplayMember = "Description" and the ValueMember = "ID".
Steve
|
|
|
|
|
MS ACCESS HELP Listing -> "If the DataType property is set to Text, enter a number from 0 to 255. "
Anybody know how to deal whit this, to make it higher than 255?
Or maybe how to set Memo type at least?
Regards!
|
|
|
|
|
Access' text datatype (Varchar in oledb terms) is limited to 255 characters (unicode).
the 'memo' field type (LongVarChar) holds up to 63,999 characters.
You set the field datatype when you create the table. Some databases allow the type to be changed
with "Alter table". There are restrictions on what changes can be made whithout losing data, not sure what access supports.
|
|
|
|
|
Rob Graham wrote: You set the field datatype when you create the table.
It's obvious;)
Rob Graham wrote: There are restrictions on what changes can be made whithout losing data
There is no data in table, and the goal is, how to set the memo datatype?
There is no option to choose memo, so how to do it?
Aby ideas?
Regards
|
|
|
|
|
eMtek wrote: There is no option to choose memo, so how to do it?
In the Table Designer, next to the Field Name is a Data Type column. Click in it, and you will have a drop down arrow on the right side. Click it, and choose Memo. It's obvious.
--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
|
|
|
|
|
EricDV wrote: Click it, and choose Memo.
Yeah I know it's obvious;P
But..., the problem was with translation (in mine Access "memo" is as a "note") used in Access. Datatype's name in any way points to memo datatype for me. So, I was confused, but now I konow.
Thanks
|
|
|
|
|
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
|
|
|
|