sql

How to migrate from my WAMP environment to using MSSQL?

I have on my local PC installed WAMP environment (using WampServer OS). Now I would need to change one script from working with MySQL to MSSQL. I have no idea at all how to proceed, where to download MSSQL, how to install it and how to connect with PHP? Thank you very much ...

How do I call a User Defined Function to use with select, group by, order by?

I have Table1 and I need to get it to look like Table2: Table1 VisitingCount | Date ----------------------- 1 | 15:09 3 | 15:10 7 | 15:15 1 | 15:39 2 | 15:40 3 | 15:47 Table2 VisitingCount | Date ----------------------------- 11 | 15:00-15:30...

Force Package Failure From Send Mail Task in SSIS

Is there any way to force a package to fail from a Send Mail Task? We have a package whose last step is to send a failure message using the Send Mail Task if certain criteria are met. Usually, we create another Script Task directly after the Mail Task which just fails the package using code: Dts.TaskResult = Dts.Results.Failure Is the...

displaying a table's field in a textbox

I have a table and I want to select a field in it and then display it in a text box something like: SELECT userName FROM userTable WHERE (userLogged = 'ON') how can I display the selected username in a textbox? BTW the userLogged indicates wether the user is logged in or not if the user is logged in then the userLogged will be chan...

T-SQL - What is an inline-view?

I recently answered this question how-to-call-user-defined-function-in-order-to-use-with-select-group-by-order-by My answer was to use an inline view to perform the function and then group on that. In comments the asker has not understood my response and has asked for some sites / references to help explain it. I've done a quick googl...

Java/Servlet: get current sql.Date

What I need to do is: 1) Get user's locale from request. 2) Create new sql.Date object with current date and time, based on user's locale 3) Write it in MySQL db, column type: TIMESTAMP What I got is: java.util.Locale locale = request.getLocale(); java.text.DateFormat dateFormat = java.text.DateFormat.getDateTimeInstance( ...

How do I check if a temporary table exists in SQL Anywhere?

I want to write a SQL IF statement that checks whether or not a local temporary table exists, but those kinds of tables are not recorded in the SQL Anywhere system catalog. ...

Getting the field and table name that caused an exception from a SQL Exception object

I'm using Hibernate JPA and Spring in my project. Suppose if I try to insert a record with duplicate key value, the insert query will throw an exception. Now, is it possible to get the table name, field name and possible cause for the exception from the SQL Exception object at run time !? ...

Prevent recursive CTE visiting nodes multiple times

Consider the following simple DAG: 1->2->3->4 And a table, #bar, describing this (I'm using SQL Server 2005): parent_id child_id 1 2 2 3 3 4 //... other edges, not connected to the subgraph above Now imagine that I have some other arbitrary criteria that select the first and last edges, i.e. 1->2 a...

How do I decrease the size of my sql server log file?

So I have been neglecting to do any backups of my fogbugz database, and now the fogbugz ldf file is over 2 and half gigs. Thats been built up over the six months we've been using fogbugz. I backed up the database, then I backed up, and truncated the transaction log, yet the transaction log is still 2 and a half gigs. I did a shrink on t...

Equivalents to SQL Server TOP

In SQL Server, TOP may be used to return the first n number of rows in a query. For example, SELECT TOP 100 * FROM users ORDER BY id might be used to return the first 100 people that registered for a site. (This is not necessarily the best way, I am just using it as an example). My question is - What is the equivalent to TOP in other da...

How accurate is Oracle's EXPLAIN PLAN?

Are there any good ways to objectively measure a query's performance in Oracle 10g? There's one particular query that I've been tuning for a few days. I've gotten a version that seems to be running faster (at least based on my initial tests), but the EXPLAIN cost is roughly the same. How likely is it that the EXPLAIN cost is missing ...

How to Re Format DateTime in Sql with Ceiling or Flooring method?

i need this table look please TABLE2 Table1 VisitingCount Date 1-------------------15:09 3-------------------15:10 7-------------------15:15 1-------------------15:39 2-------------------15:40 3-------------------15:47 How can i change this table below table Table2 VisitingCount Date 11-------------------15:00-15:30 6--...

How best to sum multiple boolean values via SQL?

I have a table that contains, among other things, about 30 columns of boolean flags that denote particular attributes. I'd like to return them, sorted by frequency, as a recordset along with their column names, like so: Attribute Count attrib9 43 attrib13 27 attrib19 21 etc. My efforts thus far can achieve something...

Different result with * and explicit field list?

I was exploring another question, when I hit this behaviour in Sql Server 2005. This query would exhaust the maximum recursion: with foo(parent_id,child_id) as ( select parent_id,child_id from #bar where parent_id in (1,3) union all select #bar.* -- Line that changed from #bar join foo on #bar.parent_id = foo.ch...

MySQL change type of foreign key

I am using MySQL and I have a table with an index that is used as a foreign key in many other tables. I want to change the data type of the index (from signed to unsigned integer) , what is the best way to do this? I tried altering the data type on the index field, but that fails because it is being used as a foreign key for other table...

TSQL Parameterized SPROC question

I need to write a stored procedure to update one of a set of similar columns. The columns are named 'UserField1', 'UserField2' etc. I was hoping to pass a parameter to the SPROC which would set the column to be updated. However, I can't seem to get the code correct. Here's a simplified example of what I tried (which gets me an 'Incor...

Would this SingleOrDefault() optimization be worthwhile or is it overkill / harmful?

I was messing around with LinqToSQL and LINQPad and I noticed that SingleOrDefault() doesn't do any filtering or limiting in the generated SQL (I had almost expected the equivalent of Take(1)). So Assuming you wanted to protect yourself from large quantities accidentally being returned, would the following snippet be useful or is it a...

T-SQL: Round to nearest 15 minute interval

What's the best way to round a HH:MM value to the closest 15 minute interval? I don't track seconds so they don't matter. 00:08:00 becomes 00:15:00 00:07:00 becomes 00:00:00 01:59:00 becomes 02:00:00 and so on. Is there an elegant, non UDF or Case statement method for doing this? Thanks, James EDIT: Here's the SQL I'm using to ...

SQL Server Non-Standard Date Based Histogram

I have user login data with timestamps and what I would like to do is get a histogram of logins by year, but with the year starting at an arbitrary date. For example, I want the following sort of information: 1 May 2005 - 30 Apr 2006 | 525 1 May 2006 - 30 Apr 2007 | 673 1 May 2007 - 30 Apr 2008 | 892 1 May 2006 - 30 Apr 2009 | 1047 Th...