Viewing 15 posts - 226 through 240 (of 395 total)
It's truncation of intermediate results.
Using Decimal data type will fix it:
-------------------------------------------------------------------------
DECLARE @A Int, @b-2 Int, @C Int;
SELECT @A = 9,
@b-2 = 3,
@C = 2;
SELECT Cast(SUM(@A*@B) / SUM(@C) AS DECIMAL(30,5));
SELECT Cast(SUM(@A*@B)...
September 28, 2012 at 3:13 am
Money & Smallmoney both have 4 decimal places, so that's why they lose the detail. If you're looking for accuracy it's better to use decimal.
It's all a bit of...
September 27, 2012 at 11:05 am
Have a look at sp_MSForEachDB.
It's an undocumented sp which runs code against each db. There are plenty of examples if you search this site.
September 27, 2012 at 10:58 am
konuridinesh (9/27/2012)
can we write this into sub query?what i mean is
select * into <new table> from ( <sub query>)
Why do you want to do that?
September 27, 2012 at 10:42 am
I think the intermediate result from @v1 / @v2 is being truncated because you're using smallmoney data type.
Can you use a different datatype, or cast one value to decimal to...
September 27, 2012 at 10:40 am
SELECT a.name, b.type, MAX(b.backup_finish_date) LastSuccessfulBackup,
CAST((GETDATE() - MAX(b.backup_finish_date)) AS NUMERIC(5, 2)) IntervalInDays
INTO NewTable
FROM master..sysdatabases a
LEFT OUTER JOIN msdb..backupset b ON a.name = b.database_name
GROUP BY a.name, b.type
ORDER BY a.name, b.type
September 27, 2012 at 10:28 am
How about adding 2 rows to the ORDER BY statement? See 'Example'.
--================ TEST DATA ==========================
if object_id('dbo.tblGISStreetIndex') is not null
drop table dbo.tblGISStreetIndex;
create table dbo.tblGISStreetIndex
(
FirstName Varchar(40),
LastName Varchar(40),
StreetName Varchar(40),
AddFrom Varchar(40),
AddTo Varchar(40),
Maintainer Varchar(40),
LCity Varchar(40),
RCity...
September 27, 2012 at 9:30 am
Can you post a more complete statement so it's clearer what you're doing?
September 27, 2012 at 8:40 am
You could use a table-valued parameter perhaps?
September 27, 2012 at 7:25 am
That's a bit more complicated:
I've used CTEs because I want to refer to CTE1 twice.
The ints do not need quotes in their definition, so I've removed them.
DECLARE @tab TABLE
(
flag1...
September 26, 2012 at 10:29 am
Try this:
if object_id('dbo.MasterDefects') is not null
drop table dbo.MasterDefects;
if object_id('dbo.Results') is not null
drop table dbo.Results;
create table dbo.MasterDefects
(
Department Varchar(20),
Process Varchar(20),
Type Varchar(20),
Defect Varchar(20)
);
insert dbo.MasterDefects values ( 'Timber', 'CrossCut', 'Wood Fault',...
September 26, 2012 at 9:14 am
DELETE table FROM table... is used when you want to use a something like a select statement with joins (usually) to control which records you delete. You leave off 'SELECT...
September 26, 2012 at 9:04 am
Viewing 15 posts - 226 through 240 (of 395 total)