Date difference in Days,hours minutes and seconds.
Hi All,I have two date Suppose one is getdate() and other one is gatedate() +1 .I have to show the difference, currently I used a datediff in the stored proc which just shows the difference of the days...
View ArticleBest way to give a default value to a New Column with existing rows
Adding some columns to SQL tables with existing data rows. There are also views created from these tables. The views are used in some report/query software so NULL values are not good. Interested in...
View ArticleArithmetic overflow error converting numeric to data type numeric.
Hi I have a below scenario,DECLARE @zero_num numeric(5,4) SET @zero_num = 0.00SELECT colA,colB,@Zero_num as ratio ,colC into #tmp FROM table UPDATE #tmp SET ratio = colA/ colb WHERE colC 0Select *...
View ArticleQuery runs in management studio but not in SQLAgent job
I have the following query which runs fine in Management Studio but when I put it in a SQLAgent job it fails sayingError formatting query, probably invalid parameters (SQLState 42000 Error 22050)I have...
View ArticleCould not find prepared statement with handle %.
Greetings. I've seen several posts for this error on the web, but no clear cut answers. I captured the code below in profiler, with the intention of replaying in mgmt studio.However, the attempt end in...
View ArticleT-SQL Query logic
Hi All,I have a logic that need an idea.I work in a health care industry we deal with claims in SQL server. There will paid claims pended claimsNow I am working on pended claims. Below is the scenario...
View ArticleHow to convert a string to date using OLEDB function?
Is there any function similar to OCIDateFromText()?I have to read the date from a text file and store it in the sql database in a date column.Please suggest how to do it?Thanks in Advance.
View ArticleReturning All records from left table in sql server select statement
Hi All,I have a requirement where the table design is like belowTable PCcolA_PKcolB1 aa2 bb3 cc4 ddTable PSCcolC_PKcolA_FKColD1 1 qwe2 1...
View ArticleHow to reduce time while deleting more than 300K records ?
Hi,I am using SQL SEVER 2008 R2. I've a doubt, if there any possible to reduce executing time while deleting more than 3 lakhs records. I will explain about the table structure. Table_Name : test. In...
View ArticleSaving an invoice header and details in sql in one stored procedure.
I would like to create an invoice in visual studio 2008 with a header and x amount of details (every time it's different). I want to be able to bring it all into sql encapsulated in one begin and...
View ArticleIterate A Table and execute statements
Hello, For each row in table X I need to write an T-SQL statement that deletes rows in 5 tables. It should look something like this:declare myInt =0(foreach row in table x){delete * from table y...
View ArticleSQL query for Bitwise operation via SSRS
I am trying to write a query to display data in a SSRS report where we can select multiple values from a list parameter.The WHERE clause in the query has to filter based on the selected values with the...
View ArticleI Want Execute This T_SQL And Have Problems What Should I DO ?
-- Batch submitted through debugger: SQLQuery1.sql|0|0|C:\Users\Sahel\AppData\Local\Temp\~vsC87D.sql create proc [dbo].[sp_create_database] @DBname varchar(10), @Filename varchar(max), @ERROR...
View ArticleHow to get Current Quarter and Fiscal Quarter for a Date - Fiscal Year starts...
Hi, I need to calculate current quarter and fiscal quarter in my Sql query.I have a column for DateTime Datatype. I need to find out Current Quarter Name like Q12012, Q22012, Q32012, Q42012 and Fiscal...
View ArticlePRINT within WHILE loop is not being displayed...
Suppose I have a SQL block like the following. I added a PRINT so that I know that the process is running correctly and it's not in an infinite loop. Unfortunately, when I execute the script (and this...
View Articlesql stored procedures
Hello,I have a main stored procedure SP with 3 stored procedures SP1, SP2, SP3 in it.If one insert statement in SP2 throws an error, will SP, SP1 & SP3 execute?Even one insert statement in one...
View Articleshrink file (log) from within a procedure
I'd like to incorporate the DBCC shrinkfile command to my maintenance procedure. This procedure gets called after I've finished my weekly importing process. I only need to shrink the log files as...
View ArticleUsing Return to exit stored procedure, but SQL Agent marks as successful. How...
SQL Server 2008R2.I have a stored procedure which uses an IF/ELSE statement. This runs inside a SQL Agent job In the IF section, I check for the value of a parameter. If the value is NULL, I want to...
View Articlesys.messages 14696 begins with a leading space
In my installation, message ID 14696 for Lang 1033 begins with a space:' Cannot update or delete a system collection set, or add new collection items to it.'Please move the correct forum/suggestion...
View ArticleSimple query returns wrong results in Sql 2012
On my Windows 8 box running Sql 2012 11.0.3128, this query returns an IncludeCount of 0 and an ExcludeCount of 1. On my Windows 7 box running Sql 2008 10.50.2550 this query returns an IncludeCount of 3...
View Article