|
Hi,
I have a table whose data is displayed in a datagrid as follows
Emp_id Emp_name Other_data
12 aa ...
13 bb ...
14 cc ...
Is there any way that instead of writing a query for each and every record,
i can use a single query for updating all records..? (The data is updated in bulk)
The backend being used is MYSQL so using arrays in a procedure is not working.. i supose it is not supported in MySQL..
Thanks.
-- modified at 4:25 Monday 30th April, 2007
|
|
|
|
|
i want to use Distincts keyword to Extract rows in a property table, i dont want to select a certain column but all based on one Column Lis_key
select * from property where
Vuyiswa
|
|
|
|
|
SELECT DISTINCT Column1, Column2, etc FROM MyTable
|
|
|
|
|
Thanks For you reply
cant i say something like * that will slect all the table distinctively?
or i have to SELECT DISTINCT Column1, Column2, etc FROM MyTable
and write down all the columns i have in my table, in my case there are more than 15 columns
?
Vuyiswa
|
|
|
|
|
Vuyiswamb wrote: cant i say something like * that will slect all the table distinctively?
SELECT * is inefficient and the result set will change if you change your database. You are better to specify the columns that you want.
Vuyiswamb wrote: and write down all the columns i have in my table, in my case there are more than 15 columns
Just 15... Then you don't have much to do. A project I worked on a couple of years ago produced result sets with over 200 columns, all individually named.
|
|
|
|
|
Thank you Very much it Helped
Vuyiswa
|
|
|
|
|
A good opportunity to find a way of getting a list of column names for that table from the DB.
|
|
|
|
|
Hi Folks,
I am unable to locate the SqlHelper Class in the Enterprise Library Release April 2007. Can Somebody tell me where exactly I can find the source code , I actually wanted to understand the source code more in order to use it efficiently.
Thanks,
Happy Programming!
Regards,
Nikhil Pagidala
|
|
|
|
|
I've not looked at this version of the Enterprise Library, but didn't they take that out in version 2?
|
|
|
|
|
I am not sure about the Jan 2007 release coz so far I was using the June 2005 release.
Can you please let me know if you get any info.
Thank You!
Happy Programming!
Regards,
Nikhil Pagidala
|
|
|
|
|
Nikhil Pagidala wrote: Can you please let me know if you get any info.
Why don't you just read up on how the Enterprise Library now works rather than how it used to work? There should be plenty of documentation and tutorials on the Microsoft site.
|
|
|
|
|
i have a "Booking" table with 3 Column:
BookingID (numeric - primary key)
CheckInDate (datetime)
CheckOutDate (datetime)
- With input are indate and outdate, i want select out free date range in Booking table, like find free room for hotel booking
Thanks.
|
|
|
|
|
I don't see how you can do it with this, you don't have a room number in the table.
Otherwise, you need to use the date functions in SQL to find which rooms are booked on a given date, or a given range, and return the other room numbers.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Can you show me some db design and algorithm about hotel booking? i tried search a hours but...
Thanks.
|
|
|
|
|
I'm not really sure what to say. You should work through a book on database design, and think your problem through. The SQL Server help has all the info you need on how to use date functions.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
<pre><code> :-O :zzz: :-\ :(( :-O :omg: :mad::confused::~ :doh: </code>
|
|
|
|
|
Hi,
Is it possible to make a stored procedure sort columns either ascendingly or descendingly base on a parameter? If not, should we ignore taking advantage of stored procedures and build dynamic SQL commands instead? (building a dynamic sql string in our stored procedure and then calling EXEC())
We don't want to use dynamic SQL commands due to two reasons:
1- preventing SQL injection vulnerability
2- stored procedures containing dynamic SQL are compiled everytime we execute them, which I think should be avoided as far as possible
thanks for any help
|
|
|
|
|
U can use if condition to test the argument
and write 2 select commands like:
if(@order=1)
select .... order by asc
else
select .... order by desc
Do U really need this or I am wrong somewhere?
Regards,
Arun Kumar.A
|
|
|
|
|
Yes this works, the problem is that for two large blocks of select statements, I should copy the whole select block and paste it into 'else' section of if statement just because I wanna sort it descendingly, it's a little annoying, isn't it?
It would be nice if there was a way to enclose the ASC/DESC section of our sql, something like this:
select * from books order by title
if(@order=1)
asc
else
desc
|
|
|
|
|
select * from books order by
case when(@order=1) then title end, asc
case when(@order=2) then title end, desc
Hope, this helps U.
Regards,
Arun Kumar.A
|
|
|
|
|
I have tried this with the folloing example by changing @a to 1 or 0 alternatively:
It works fine.
declare @a int
set @a=1
select * from tableName
order by case
when @a=0 then columnName
end ,
case
when @a=1 then columnName
end desc
But the problem is we have to design the conditons in such a way that only one of the conditions must evaluate to true.
Change the value "0" to "1" in the above code.
It will throw U an error.
So, please make sure to check the above problem.
Regards,
Arun Kumar.A
|
|
|
|
|
Thank you, this seems to help solve the problem we have,
I just didn't understand what the need of ',' is after the first when statement here:
when @a=0 then columnName
end ,
why sould we use ',' when we have shown the end of WHEN block with an 'end' keyword? I also tried this and it worked:
when @a=0 then columnName
end asc,
Maybe I'm just not familiar enough with CASE WHEN statement syntax in sql! shame on me!
Just one more question, Is there also a way to select different columns conditionaly too? (I mean something like the second solution you offered, just by enclosing a specific part of our select statement)
|
|
|
|
|
Maysam Mahfouzi wrote: Is there also a way to select different columns conditionaly too?
Yes, using simple case we can do that.
Click here
R U asking this?
Or do U want to sort by different columns based on condition?
Regards,
Arun Kumar.A
|
|
|
|
|
The trouble with this approach is that SQL Server generates and caches an execution plan the first time you run a stored procedure, then reuses that execution plan every time until it hasn't been used for long enough to be discarded. Only on the next execution will it then be recompiled.
If you have one of these amorphous stored procedures, where the behaviour is very different - effectively using different columns in the WHERE or ORDER BY clauses - the cached execution plan for one set of parameters can be very wrong for a different set. This translates into bad and unpredictable performance. You can force compilation of the execution plan every time by specifying WITH RECOMPILE , but obviously you incur the overhead of computing the execution plan every time it's executed.
It may well be better to use dynamic SQL explicitly from the client. You can still prevent SQL injection by using replaceable parameters in your SQL query text, and this will actually improve execution plan compilation times as SQL Server prefers retaining execution plans from parameterized versus non-parameterized queries (SQL Server caches all computed execution plans unless specifically told not to, but gives greater weight to stored procedures over parameterized text over non-parameterized text, so the more structured queries are retained longer).
You do lose the access control benefits of stored procedures as the user account used to query the database must be given SELECT access to the tables being queried (rather than just GRANTing access to EXEC the stored procedure).
|
|
|
|
|
Or, you can build the string within the proc, and get the same result without the loss of access control ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|