sql

SQL: SELECT IN faster and best practice?

if i m using 2 queries: first: queries all keys/ids required second: select * from tab1 where tab1.id in (...ids list..,,) ids list can be several thousands... is it wise or best practice or recommended to do things like that? ...

Copy table structure into new table

Is there a way to copy the structure of a table into a new table, without data, including all keys and constraints? ...

Different types of WAMP's?

"WAMP" is an acronym formed from the initials of the operating system (Windows) and the package's principal components: Apache, MySQL and PHP (or Perl or Python). Personally I use XAMPP Lite, but thats because I haven't tried anything else. I've just been looking as to how to install SQLBuddy on it, and can't find out. I've heard about...

How do I UPDATE TOP 5, using a subselect?

Hello: I was surprised to see that the following updated 34 rows...not 5: UPDATE Message SET StatusRawCode = 25 WHERE StatusRawCode in ( Select TOP 5 M2.StatusRawCode From Message as M2 Where M2.StatusRawCode = 5 ) Any ideas on how to pound this into the right shape? Thank you! ...

Select query takes 3 seconds to pull 330 records. Need Optimization

Hi all, I have and normal select query that take nearly 3 seconds to execute (Select * from users). There are only 310 records in the user table. The configuration of the my production server is SQl Server Express Editon Server Configuration : Pentium 4 HT, 3 ghz , 2 GB ram Column Nam Type NULL COMMENTS Column Nam Type NULL...

tcp\ip server tracking database changes

I have a tcp\server ( .NET 3.5 ) that notifies connected clients about aah interesting events. These events occur because an aspx website is writing stuff to a database( SQL 2005 ) What would be a good way for this server to monitor the database so to speak can the db push info to the server in any way? any suggestions thoughts welcome ...

Selecting data in MySQL and limiting (WHERE) by temporary column data

I am trying to sort order-entries by their status, however in my database there is no column for status and I'm trying to generate it on-the-fly with current values on other columns in the database. I've created a "temporary" column in my query with a CASE-statement. What I want to do now is get only the table rows that match the value ...

Ratings to the items based on user click

Hi, I am trying to have a ratings strategy in the hotels search website.Ratings is based on number of clicks by the users who view different hotels.I am trying to assign number of points to each click. Suppose i have a POINTS column in the hotels table which increases by the number of clicks on each hotel, the problem i face is suppose...

Count(*) vs Count(1)

Hi, just wondering if any of you guys use Count(1) over Count(*) and if there is a noticeable difference for SQL Server 2005 in performance? Or is this just a legacy habit that has been brought forward from days gone past? ...

How do I update a XML string in an ntext column in SQL Server?

have a SQL table with 2 columns. ID(int) and Value(ntext) The value rows have all sorts of xml strings in them. ID Value -- ------------------ 1 <ROOT><Type current="TypeA"/></ROOT> 2 <XML><Name current="MyName"/><XML> 3 <TYPE><Colour current="Yellow"/><TYPE> 4 <TYPE><Colour current="Yellow" Size="Large"/><TYPE> 5 <...

SQL - Query Phonenumber that are stored inconsistently

Hi, we a phonenumber field in our database and I would like to do a simple lookup query like: SELECT * FROM TABLE WHERE Phonenumber = '555123456' But since the phonenumbers are entered by users and are not normalized, we don't really know what they look like. Could be: +555-123456 or (555) 123 456 or 555-12-34-56 or som...

loop through $_GET results

Hi, If I had something like this: ?FormSub=Submit&qty=1&partno=ipod&notes=apple&unitprice=102.99&rowid=1&qty=2&partno=Ear+Buds&notes=Headphones&unitprice=45.99&rowid=2 Is it possible to loop through the GET's to return results into a HTML table and also add to a SQL table? Or would I need to add the rowid to then end of every $_GET ...

Post build on database project

In Visual Studio 2008, I have this database project to manage my SQL Server 2008 database. This has a prebuild and postbuild SQL Script that contains an example like this: :r .\myfile.sql What does this mean? ...

SQL Server 2005 - SQL Statement to remove clustered keys from tables based on a query on tablenames?

I am trying to restore a backup of a Microsoft Dynamics NAV database, which unfortunately fails as it tries to set a CLUSTERED KEY for the tables which already have clustered keys. In NAV, every company in the database gets its own copy of the tables, prefixed with the Company's name, e.g. COMPANY$User_Setup. I'd therefore like to remov...

MySQL Join excluding certain records?

Hi, i'm trying to build a join, but I can't get it to work in MySQL, I know there must be a way. I have two tables: 1. Setting and 2. User_Setting (and ofcourse User but that won't be needed here). Structure Setting.setting_id Setting.description Setting.value_type Setting.default_value User_Setting.user_id User_Setting.setting_id ...

INSERT INTO wont work!

im having some problem with this code: if (count($_POST)) { $username = mysql_real_escape_string($_POST['username']); $passwd = mysql_real_escape_string($_POST['passwd']); mysql_query("INSERT INTO users (username, password) VALUES ($username, $passwd)"); } <form method="post"> <p><input type="text" name="username" /></...

sql query, wildcard, MS SQL SERVER 2005

I need my query to pull all DirName's what have the following prefix 'site/test/test/' is the correct syntax a '*' SELECT DirName, count(*) AS FileCount, SUM(Size)/1024 as 'SizeKB' FROM alldocs Where DirName = 'site/test/test/*' GROUP BY dirName ORDER BY DirName ...

What is the type of XQuery passed to SQL Server XML Data Type methods?

According to BOL on value() Method (xml Data Type), value() method takes two arguments XQuery SQLType Do I need to pass varchar or nvarchar to value()? How can I find out what kind of type XQuery or SQLType expects? End Goal: To create utility UDF/sprocs that uses XML Data Type methods. ...

SQL Server Default Instance: If you change host machine's name...

Say I have a Server named "MyServerABC", on which I have Sql Server 2005 installed with a Default Instance. Thus I can always connect to my sql server just by specifying "MyServerABC". Now, I change my server's name to "MyServerDEF". Will I now be able to connect to the sql server by just specifying "MyServerDEF"? Are there any hol...

column sum, sql, ms sql server

I'm trying to get a column total but when i run this query i get the following error. Any advice? SELECT SUM(Size) as total FROM AllDocs Where DirName LIKE 'sites/test/test%' ERROR: Msg 8115, Level 16, State 2, Line 1 Arithmetic overflow error converting expression to data type int. Warning: Null value is eliminated by an aggregate o...