|
I thought a bit more about what you're trying to do. You want to insert a record into the table if, and only if, there are no records that have int_field = '20'.
Something you could do is like this:
insert into mytable (default,number,text,date)
select 'xxx' as default,123 as number,'yyy' as text,'2006/07/14' as date)
from mytable where not exists(select * from mytable where int_field = '20') LIMIT 1
The LIMIT 1 assures that only 1 record will be inserted (because you are selecting only 1 record). The values are aliased in the select statement, because you don't want to pull values from mytable.
Using my previous example, this worked:
INSERT INTO tblpeople (firstname,lastname,age)
SELECT 'John' as firsname, 'Williams2' as lastname, 20 as age
FROM tblPeople p
WHERE not EXISTS(SELECT * from tblpeople p2
WHERE p2.firstname = 'John' and p2.lastname='Williams2' and p2.age = 20) LIMIT 1
I hope this helps.
--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
|
|
|
|
|
Thanks for the help Eric.
I'm finally getting somewhere! Thanks again buddy!
|
|
|
|
|
Is there a way to change the datetime or smalldatime format without converting it to a string?
"All men by nature desire to know."
|
|
|
|
|
The internal format is always the same - 8 bytes for datetime, 4 bytes for smalldatetime. I'm not sure what you're asking here.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
let's say from yyyy/dd/mm to mm/dd/yyyy? Is that possible without using conversion?
"All men by nature desire to know."
|
|
|
|
|
Hi,
I want a SQL query which will return result set using exact match case.
e.g.
Query1:
SELECT * FROM <table_name> WHERE <column_1> = 'computer'
This query return result set with Column1 = 'computer'
Query2:
SELECT * FROM <table_name> WHERE <column_1> = 'COMPUTER'
This query return result set with Column1 = 'COMPUTER'
In above queries both return diff results.
Regards
Sumit
|
|
|
|
|
Did you mean you want to return results which contains both 'computer' and 'COMPUTER'?
In most SQLs the queries are case-insensitive which means both query 1 and 2 should return the same result.
If that is not the case, then just use WHERE UCASE(column1) = UCASE('Computer') so everything is search based on uppercase value.
If you want case-sensitivity instead, then just cast both values into varbinary, e.g. CAST('Computer' AS varbinary(8)).
For more information on SQL case sensitivity, you can read this link[^].
"You are special, but so is everybody else."
"Democracy is two wolves and a sheep voting on what to have for dinner" - Ross
Edbert
Sydney, Australia
|
|
|
|
|
As per your suggestion, I execute following query
SELECT * FROM TagMaster WHERE CAST('Metric' AS varbinary(6)) = CAST(TagName AS varbinary(6))
//Comment : There is a entry TagMaster where column TagName = 'Metric'
// But it return blank result set.
Then to cross check I execute following query
SELECT CAST('Metric' AS varbinary(6)), CAST(TagName AS varbinary(6))FROM tbl_UI_TagMaster
// Comment : Which gives two columns which are not matching at all.
// Like
-------------- --------------
0x4D6574726963 0x4D0065007400
0x4D6574726963 0x500072006F00
0x4D6574726963 0x410063007400
0x4D6574726963 0x500049004E00
0x4D6574726963 0x540069006D00
0x4D6574726963 0x45006D007000
0x4D6574726963 0x4C006F006300
0x4D6574726963 0x45006D006100
|
|
|
|
|
Read this[^]
Regards.
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
I'm still pretty new to the Asp.Net world.
I have a website that a user will have to fill out some forms. Several of these forms I want the entries to be standardized into drop down boxes. (for intstance, ethnicity) I'd like to be able to pull values from an 'ethnicty' table and well several other tables for other drop down boxes.
How ever I have a concern, how many sqldatasource objects is to many? (Is it common practice to use as many as 10 different sql data sources on the same webpage?)
How well does the .net code optimize these data sources? For example, on each datasource does it open a connection, run the query then close connection for all 10 sources?
In general, if I ran the queries on page load and then set the values of the drop down boxes would/could that be more efficient?
Or are there a better places than page_load to do that??
Any info on these questions would be greatly appreciated, thanks
Drathmar
|
|
|
|
|
|
You should try looking at 'Factory' class which gives you an idea how to write database agnostic [generic] code.
|
|
|
|
|
I want to select categories with biggest id from the table below. For example, Diet should return 228 and excercise should return 225... I want distinct category with biggest id.
id Category
9 Diet
218 Diet
228 Diet
8 Exercise
215 Exercise
225 Exercise
1 Investing
224 Investing
234 Investing
5 Movie
219 Movie
229 Movie
Anybody can help me??
thanks in advance
-- modified at 22:36 Thursday 13th July, 2006
|
|
|
|
|
SELECT Category, MAX(id) AS MaximumID
FROM dbo.TableName
GROUP BY category
should do the trick. that is of course assuming you are using SQL Server, best in future to specify the actual database (and version) it removes any doubt and ensures the answer you get is accurate
|
|
|
|
|
thank you very much. This is exactly what i wanted.
|
|
|
|
|
No worries, MAX is one of SQL Server's "aggregation" functions. There are lots - SUM, MIN, AVG etc etc and Grouping is a very powerful feature - definitly worth the time to look into and understand.
|
|
|
|
|
//String* con = S"Provider=Microsoft.Jet.OLEDB.4.0;" + S" DataSource=C:\\AEM\\Database\\ProTunerDatabase.mdb";
OleDbConnection* ole = new OleDbConnection( S"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\AEM\\Database\\ProTunerDatabase.mdb" );
//OleDbDataAdapter* dadapter = new OleDbDataAdapter(S"select * from Item_List", ole);
OleDbDataAdapter* dadapter = new OleDbDataAdapter();
DataSet* dset = new DataSet();
ole->Open();
OleDbParameter* par;
dadapter->SelectCommand = new OleDbCommand(S"select * from test", ole);
dadapter->Fill( dset, S"test" );
dadapter->UpdateCommand = new OleDbCommand(S"update test set Item_name=@str where Item_id=@prev");
par = dadapter->UpdateCommand->Parameters->Add(new OleDbParameter ("@str", OleDbType::VarChar));
par->SourceColumn = "Item_name";
par->SourceVersion = DataRowVersion::Current;
par = dadapter->UpdateCommand->Parameters->Add(new OleDbParameter ("@prev", OleDbType::Integer));
par->SourceColumn = "Item_id";
par->SourceVersion = DataRowVersion::Original;
dadapter->UpdateCommand->Connection = ole;
dadapter->Update(dset,"test");
HOW DO I SPECIFY VALUES FOR @str and @prev ????
so that i can update my database.
I am using Visual C++.NET in Visual Studio 2005
Thanks,
Kedar Dave
|
|
|
|
|
dadapter->UpdateCommand->Parameters("@str")->Value = "test".
|
|
|
|
|
dadapter->UpdateCommand->Parameters("@str")->Value = "test";
I tried it....but it gave me the following errors:-
error C2064: term does not evaluate to a function taking 1 arguments
error C2227: left of '->Value' must point to class/struct/union/generic type
why do i get this?
setting par->Value = "test"; -- doesnt giv any errors but doesnt work either
Thanks,
Kedar Dave
|
|
|
|
|
My mistake. Parameres["@str"] - square brackets, not parentheses
|
|
|
|
|
i did Parameters["@str"]->Value = S"test";
but got the following when i compiled :
error C2107: illegal index, indirection not allowed
hw do i get rid of this error?
thanks a lot,
Kedar Dave
|
|
|
|
|
Hey,
we have an application written in ASP 3.0.in that we used Crystal Reports to generate reports(directly communicating with ASP).Now we want to use Sql REporting Servicesinstead of crystal Reports.I want to know whether we can use SQl Reporting services with ASp 3.0 or not.. If we can, plz send a sample or explain me how to do that. my id..
grminds@yahoo.com
Thanks in advance..
|
|
|
|
|
|
To best of my knowledge you can build web and smart client using reporting services from VS 2005 development platform. Since you are using ASP3.0 which I assume not asp.net, then I guess try exploring options of web services interface provided by ms reporting services.
Hope this helps.
Difficult - > Challenging, this simple replacement made me take my life little easy;)
|
|
|
|
|
Hi, i'm having a bit of trouble with this query:
"select SUM(t1.value1 - SUM(t2.value2)) from table1 as t1, table2 as t2 where t1.prop=0 and t1.payed=0 and t1.date='2006-3-21' and t2.parent=t1.id";
I can't retrieve the SUM(t1.value1 - SUM(t2.value2)) because i don't know where to insert the group by and what should i group for. I was able to retrieve (t1.value1 - SUM(t2.value2)) if i group by t1.id (wich is the column index) but adding the SUM it doesn't work. Ignore the conditional values, i'm having troubles with the SUM(t1.value1 - SUM(t2.value2)) part.
Thanx if someone can helpe me with this one.
-- modified at 16:57 Thursday 13th July, 2006
|
|
|
|