sql

SELECT SQL Variable - should i avoid using this syntax and always use SET?

Hi All, This may look like a duplicate to here, but it's not. I am trying to get a best practice, not a technical answer (which i already (think) i know). New to SQL Server and trying to form good habits. I found a great explanation of the functional differences between SET @var = and SELECT @var = here: http://vyaskn.tripod.com/diff...

SQL question - Cursor or not?

Hi, I have a query which returns 2+ rows. In those results is a column which we can call columnX for now. Lets look at those example results: columnX 100 86 85 70 null null I get 6 rows for example, some of them are null, some of them are not null. Now I want to go through those results and stop as soon as I find a row which is <> null...

Find the period of over speed ?

Just something interesting come in my mind. Assume that we have a table (in SQL Server) like this: Location Velocity Time for example: Location Velocity Time 1 40 1:20 2 35 2:00 3 45 2:05 4 50 2:30 5 60 2:45 6 48 2...

Hi can anyone try how to solve the query for this table structure???

Employee table structure first_name varchar2(100) last_name varchar2(100) hire_date date show all the employee who hired on the day of the week on which highest number of employees were hired? ...

SQL programming interface to external storage application

My application is a non-relational database application with a tcl interface to retrieve data. I would like to add SQL programming interface to my application. Is there any library that converts SQL/PLSQL statements to API calls? It should also support stored procedures. SQLite(Embedded) has 'virtual table' mechanism that suits my req...

How to distinguish between the first and rest for duplicate records using sql ?

Hi, These are the input table and required output table. Input table ID Name ------------- 1 aaa 1 ababaa 2 bbbbbb 2 bcbcbccbc 2 bcdbcdbbbbb 3 ccccc Output table ID Name Ord ----------------------------- 1 aaa first 1 ababaa ...

Unix timestamp VS datetime

I have a Mysql table, which has a column add_date. It tracks the date/time when the record was added to the database. Queries based on this table: Display when the record was added in the format: 2 hours ago, 4 weeks ago, 1 year ago etc Allow users to search records inserted in any day/month/year. So the user may be allowed to choose...

Is it possible to get all triggers associated with a table using sql server 2008 clr programming?

Hi All, Is it possible to use .net (C# SQL CLR) to find all the triggers associated with a table? And also will I be able to determine the type of that trigger? - CLR or T-SQL? Thanks, Chaks ...

Question about SQL clause

Hi, I have a database with names like this: Maria Garcia Garralon Jose Maria Perez Gutierrez I have a filter also to search the names. Imagine the user write in the filter maria garralon (the first and the last words) In that case, is there any SQL clause that finds the record "Maria Garcia Garralon" ? Regards Javi ...

Better way to summarize data about stop times?

This question is close to this: http://stackoverflow.com/questions/2947963/find-the-period-of-over-speed Here's my table: Longtitude Latitude Velocity Time 102 401 40 2010-06-01 10:22:34.000 103 403 50 2010-06-01 10:40:00.000 104 405 0 2010-06-01...

SQL query performance optimization (TimesTen)

Hi community, I need some help with TimesTen DB query optimization. I made some measures with Java profiler and found the code section that takes most of the time (this code section executes the SQL query). What is strange that this query becomes expensive only for some specific input data. Here’s the example. We have two tables that ...

Mysql query help needed

Hi, i have two tables category and hotels where category.id should be equal to hotels.catid. Now how do i select 3 rows from each different category from the hotels table. I have this query: select h.* from hotels h inner join category c on h.catid = c.id order by h.catid, h.hid this selects all records, but i want to select three r...

Disable Primary Key and Re-Enable After SQL Bulk Insert

I am about to run a massive data insert into my DB. I have managed to work out how to enable and rebuild non-clustered indexes on my tables but I also want to disable/enable primary keys as I believe this will speed up the insertion process. NOTE: This is over numerous tables and so I assume I need some loop to get the primary key info...

Unable to access SQL reporting services on shared site with Themes enabled

Hi, I am having some trouble with my IIS web server & SQL reporting services. At the current time my site is playing host to both reporting services (/reports & /reportserver) as well as my personal website (domain.com) Only just recently have I implemented a Theme on my site and as such I have placed a statement in my web.config file ...

HowTo: Update DB row with save for prior to change state

Hi, i have a table with order details. User is able to modify these details after he adds them for first time. My question is what is more right way to save prior to update changes. By that i mean not just subjective way of thinking but drawbacks in each way i list or maybe your suggestion... I thought of creating Orders history table w...

Doctrine: how to create a query using "LIKE REPLACE" ?

Hi, this SQL clause is working OK: SELECT * FROM `sf_guard_user` WHERE nombre_apellidos LIKE REPLACE('Mar Sanz',' ','%') Now I'm trying to write this query for Doctrine. I have tried this: $query->andWhere(sprintf('%s.%s LIKE REPLACE (?," ","%")', $query->getRootAlias(), $fieldName), 'Mar Sa...

SQL code editor with syntax highlighing, auto-formatting and code folding

Hello, Is there any SQL editor that supports syntax highlighting, automatic code formatting and code folding? I found this, but it's an Eclipse plugin (I'm a NetBeans user), and cannot automatically format code, which is the most important feature I'm after. Autocompletion is not important, nor is the possibility of running the code (l...

Find units with zero categories

Hello, I am after an SQL command to find units with no categories. Here are the tables: Unit id name UnitCategory id name UnitCategoryIndex id categoryid unitid Thanks! ...

Difference between SET autocommit=1 and START TRANSACTION in mysql (Have I missed something?)

Hey there, I am reading up on transactions in mysql and am not sure whether I have grasped something specific correctly, and I want to be sure I understood that correctly, so here goes. I know what a transaction is supposed to do, I'm just not sure whether I understood the statement semantics or not. So, my question is, is anything wron...

SQL error - Cannot convert nvarchar to decimal

I have a C# application that simply parses all of the txt documents within a given network directory and imports the data to a SQL server db. Everything was cruising along just fine until about the 1800th file when it happend to have a few blanks in columns that are called out as DBType.Decimal (and the value is usually zero in the files...