sql

How to format keywords in SQL Server Full Text Search

I have a sql function that accepts keywords and returns a full text search table. How do I format the keyword string when it contains multiple keywords? Do I need to splice the string and insert "AND"? (I am passing the keywords to the method through Linq TO SQL) Also, how do I best protect myself from sql injection here.? Are the de...

How to select bottom most rows?

I can do SELECT TOP (200) ... but why not BOTTOM (200)? Well not to get into philosophy what I mean is, how can I do the equivalent of TOP (200) but in reverse (from the bottom, like you'd expect BOTTOM to do...)? ...

How to put the Order BY in SQL UNION so TOTALS will show up always as last row?

I have SQL UNION where second part of that statement is the row that represents TOTALS. How can I ORDER BY where TOTALS will ALWAYS will show up as the last row? ...

MySql Question - way to update portion of a string?

I'm looking for a way to update just a portion of a string via mysql query. For example, if I have 10 records all containing 'string' as part of the field value (i.e., 'something/string', 'something/stringlookhere', 'something/string/etcetera', is there a way to change 'string' to 'anothervalue' for each row via one query, so that the...

Parse/Shred Huge Complex XML to SQL Server 2008 Database (30+ tables)

I read this already: http://stackoverflow.com/questions/61233/the-best-way-to-shred-xml-data-into-sql-server-database-columns and http://stackoverflow.com/questions/223376/looking-for-a-good-bulk-insert-xml-shredding-example-for-sql-2005. The differences of why I'm posting is that I'm using BizTalk 2009 and SQL 2008. I'm receiving ...

VARBINARY output in MS MGMT Studio different than Powershell/.NET

I'm in a bit of a situation with outputting data from a table where the only column I'm selecting is a VARBINARY(MAX) type. In management studio, when I execute the query, I get back what I expect in the format: 0x1FABCDEFG......etc Now, when the same query is executed in powershell, via a simple setup of a SqlCommand, SqlDataAdapter...

Will the following three queries ALWAYS produce exactly the same results?

hi We want all members who selected category 1 as their favorite category to also have category 9 added as one of their favorite categories. I assume the following three queries will ALWAYS produce exactly the same results ( assuming FavCategory.CategoryID and FavCategory.MemberID form a primary key ): SELECT 9, md1.MemberId FROM M...

I need help with a Rails ActiveRecord Join - I know how to do it in SQL

I have 2 tables I need to join but the user_id column value is not the same in both tables. So I want to do something like this: In my controller 4 will be substituted with current_user.id select * from sites join pickups on sites.id = pickups.site_id where sites.user_id = '4' But using an ActiveRecord Find. Here are my association...

mySQL ORDER optimizing

I have a query in which I am ordering a league table by a number of fields to handle the situation that some fields in the result may have the same value. I am curious as to why when subsequent fields aren't required for secondary ordering the query is still conciderably slower. Case in point is a table of items that are voted on. It co...

Help with a SQL Query

Hi, I have been trying to think of a way to retrieve some data from a database by way of a SQL query. I am trying to avoid doing it programatically. essentially the source table is ID,DateTime,Count I want to get the sum of the count for a defined period of DateTime for each distinct ID within that period. Any ideas people? ...

SQLCMD running as builtin Admin Group

How to run SQLCMD with builtin Administrator Group. ...

How to fill date gaps in MySQL?

How i can fill date gaps in MySQL? Here is my query: SELECT DATE(posted_at) AS date, COUNT(*) AS total, SUM(attitude = 'positive') AS positive, SUM(attitude = 'neutral') AS neutral, SUM(attitude = 'negative') AS negative FROM `messages` WHERE (`messages`.brand_id = 1) AND (`messages`.`spam` = 0 AND `mess...

Help designing small database.

I have a small database that I need help designing. I have a VB.NET program that gets data from a .csv file and enters the data into an Access database. The data is from a "Runway Friction Test". A machine measures the level of friction on a runway due to rubber build up from airplanes landing and puts the data into a .csv file. I n...

MySQL Query Question.. I give up!

*UPDATE, seems like the answer was given, but the SQL query his erroring out.. can anyone help? See the first answer, i posted the problem there. So to put this simply. I have 3 tables. An "item" table and a "tag" table. Then I also have an "item_tag" table which ties the 2 together. I want to make a query that lists all the items ...

One to many mySQL database setup

I'm having trouble wrapping my head around how to set this up. I have two tables: Projects Sections 1 project can belong to many sections. 1 section can have many projects. How would I go about setting this up, would this be a many to many relationship or one to many? Would it best if I created a lookup table? ...

SELECT from two same table with intersect

The query: SELECT id_user FROM Rating Where id_movie=2 INTERSECT SELECT id_user FROM Rating Where id_movie=3 but I get: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTERSECT SELECT id_user FROM Rating Where id_movie=3 LIMI...

HTML5 localStorage & SQL

I understand that HTML5 "localStorage" is a key:value store but I am wondering if there is a Javascript library available that offers a more SQL-ish API? ...

Make query results links in PHP

I'm trying to turn some query results into click-able links through PHP. I'm a beginner and don't really know much. I'm working with Wordpress. Here's what I'm shooting for: http://www.celebrything.com/ The right side bar is display the count results. I'd like the celebrity names to link to search links for each name. so the first shou...

Exist a sample or template database for BI about sales/inventory?

I will start a reporting tool for some local ERPs about sales, invoices, orders, customers, inventory, etc. I wonder if exist a sample schema appropriated for this case (in star or snowflake form) so I can have a solid foundation. I have understanding about basic BI desing, but taking in account this is a common problem, I wonder if ex...

Object Design Question User and Access Role in PHP with SQL

Hi, how do you design your objects lets say you have an object user and an object access_role. The user is stored in users table in an sql database, the access_role knows the user_id and is stored in an sql database. class user() { protected $_name; protected $_id; protected $_age; protected $_password; public...