sql

extarct characters using delimiters

I am having string called '200_CFL_2010'. I wish to get the characters between _'s. I want the output as 'CFL'. I have to achieve it through SQL. Any idea please? ...

executing null values records

i am trying to execute the records that have TotalTime null value from the table NewTimeAttendance...TotalTime datatype nchar(10) select * from newtimeattendance where TotalTime = 'NULL' ....nothing select * from newtimeattendance where TotalTime = 'null' ....nothing select * from newtimeattendance where TotalTime = 'Null' .....

Daily/Weekly/Monthly Record Count Search via StoredProcedure

Using MS SQL Server.I have made a Stored Procedure named SP_Get_CallsLogged. I have a table named TRN_Call, and it has one column named CallTime which is a DateTime. I have a web-page in my application where the User enters:- StartDate (DateTime) EndDate (DateTime) Period (Daily/Weekly/Monthly) (varchar) (from DropDownList) I want ...

Update table of two different database

This is the query to update table in one database that is of other Update test.temp a, test2.temp b Set a.name=b.name Where a.no=b.no; Now I don't want to write every field i.e a.name=b.name Is there any solution? ...

SQL Server 05, which is optimal, LIKE %<term>% or CONTAINS() for searching large column

I've got a function written by another developer which I am trying to modify for a slightly different use. It is used by a SP to check if a certain phrase exists in a text document stored in the DB, and returns 1 if the value is found or 0 if its not. This is the query: SELECT @mres=1 from documents where id=@DocumentID and contains(...

maintaining query-oriented applications

I am currently doing some kind of reporting system.the figures, tables, graphs are all based on the result of queries. somehow i find that complex queries are not easy to maintain, especially when there are a lot of filtering. this makes the query very long and not easy to understand. And also, sometimes, queries with similar filters are...

Linq-to-SQL: How to perform a count on a sub-select

I'm still trying to get my head round how to use LINQ-to-SQL correctly, rather than just writing my own sprocs. In the code belong a userId is passed into the method, then LINQ uses this to get all rows from the GroupTable tables matching the userId. The primary key of the GroupUser table is GroupUserId, which is a foreign key in the Gr...

mysql procedure to update numeric reference in previous rows when one is updated

There's a table like this one ______________________ | id | title | order | |----------------------| | 1 | test1 | 1 | |-----|--------|-------| | 2 | test2 | 2 | |-----|--------|-------| | 3 | test3 | 3 | |-----|--------|-------| | 4 | test4 | 4 | '----------------------' when i introduce in my mysql sh...

check for null date in CASE statement, where have I gone wrong?

Hello, My source table looks like this Id StartDate 1 (null) 2 12/12/2009 3 10/10/2009 I want to create a select statement, that selects the above, but also has an additional column to display a varchar if the date is not null such as : Id StartDate StartDateStatus 1 (null) Awaiting 2 12/12...

SQL Server 2005 Issue Column name or number of supplied values does not match table definition.

Hello, I wish to DELETE the data from a table before performing an INSERT INTO, however I keep recieving an error stating: Insert Error: Column name or number of supplied values does not match table definition. I've also tried defining the columns the data should be entered into as part of the INSERT INTO statement, but then get issu...

Is is faster to filter and get data or filter then get data ?

Hi I have this kind of request : SELECT myTable.ID, myTable.Adress, -- 20 more columns of all kind of type FROM myTable WHERE EXISTS(SELECT * FROM myLink WHERE myLink.FID = myTable.ID and myLink.FID2 = 666) myLink has a lot of rows. Do you think it's faster to do like this : INSERT INTO @result(ID) SELECT myLink.FID FROM...

insert into select from in a table with identity column

Hi, I am using a insert into select from statement to insert the result set of a query into a table containing an identity column. I am consistently getting an error Cannot insert duplicate key row in object 'dbo.TABLE1' with unique index 'IX_TABLE1'. Please help ...

SQL Query to get Count within a Stored Proc

So i need to figure out how i can get a record count value and use that count as a new value to insert into a table. Ex: In My Stored Procedure @Count int What im looking for @Count to equal "select top (1) _fieldName from _someTable order by _fieldName Desc" Finally insert into _newTable (_fieldName) values (@Count) End ...

Why would you use "AS" when aliasing a SQL table?

I just came across a SQL statement that uses AS to alias tables, like this: SELECT all, my, stuff FROM someTableName AS a INNER JOIN someOtherTableName AS b ON a.id = b.id What I'm used to seeing is: SELECT all, my, stuff FROM someTableName a INNER JOIN someOtherTableName b ON a.id = b.id I'm assuming there's no difference ...

Accepted date format changed overnight

Since yesterday I started encountering errors related to date formats in SQL Server 2008. Up until yesterday the following used to work. EXEC MyStoredProc '2010-03-15 00:00:00.000' Since yesterday I started getting out of range errors. After investigating I discovered the date as above is now being interpreted as "the 3rd of the 1...

SQL server management studio Express

I authenicate to my SQL Server instance by logging in with a Windows account via SQL Server Management Studio. I want to change this to a SQL server login. How can I do that? ...

SSMS 2008 Add-In - Execute Query

I'm loading a sql script up to an SSMS 2008 add-in like so: ' create a new blank document ServiceCache.ScriptFactory.CreateNewBlankScript(Microsoft.SqlServer.Management.UI.VSIntegration.Editors.ScriptType.Sql) ' insert SQL statement to the blank document Dim doc As EnvDTE.TextDocument = CType(Service...

Passing Binary Data to a Stored Procedure in SQL Server 2008

I'm trying to figure out a way to store files in a database. I know it's recommended to store files on the file system rather than the database, but the job I'm working on would highly prefer using the database to store these images (files). There are also some constraints. I'm not an admin user, and I have to make stored procedures to ...

Display field from another table in SQL

I'm a newbie with SQL... Now I want to display some instances of AddrDistances from DevExpress CxGrid with SQL. Select Cast((DistanceAsMeters * 0.001) as Decimal(8,1)) DistanceAsKm, bold_id, created, fromAddress, toAddress From AddrDistance Where DistanceAsMeters = 0 and PseudoDistanceAsCostKm = 0 and not AddrDistance.bold_id i...

SQL optimization: deletes taking a long time

I have an Oracle SQL query as part of a stored proc: DELETE FROM item i WHERE NOT EXISTS (SELECT 1 FROM item_queue q WHERE q.n=i.n) AND NOT EXISTS (SELECT 1 FROM tool_queue t WHERE t.n=i.n); A bit about the tables: item contains about 10k rows with an index on the n column item_queue contains about 1mil rows also with index on n...