Making The Shift From Access SQL To 'Real' SQL ;-)

Apr 10, 2006

for the record, this is my first post and i'm not sure this is the right place to post, but it makes sence to me.

i've been spending a great deal of time with our new MS SQL server and love it but i've noticed there's a fairly large diff between the SQL i'm used to seeing in MS Access and the SQL that the server uses. as you can see by my below statement i'm starting to get the hang of this but i still run into new issues...

my question... what's wrong with my IIf statements? this is what the server spits out...

Msg 156, Level 15, State 1, Line 4

Incorrect syntax near the keyword 'LIKE'.

[ACCPAC_OESHDT].[TERRITORY] is an nvarchar(6) and contains data such as '1', '2', '3', etc...

i've tried many many variants and always have the same outcom. i've tried casting as an int, rtrim to rid the value of any possible white space, expanded versions.

oh, almost forgot... my environment is... I open the SQL Management Studio then logon to SQL Database Engine and then create a New Query.  

i'm stuck, please advise. ;-)

SELECT

ACCPAC_OESHDT.YR,

ACCPAC_OESHDT.PERIOD,

IIf([ACCPAC_OESHDT].[TERRITORY] LIKE '[1-4]','Group A',

IIf([ACCPAC_OESHDT].[TERRITORY] LIKE '[5-7]','Group B',

IIf([ACCPAC_OESHDT].[TERRITORY] LIKE '[89]','Group C','_Unknown Territory'))) AS TERRITORY,

SUM(CAST([SAMTSALES] AS MONEY)) AS Sales

FROM ACCPAC_OESHDT

GROUP BY

ACCPAC_OESHDT.YR,

ACCPAC_OESHDT.PERIOD,

IIf([ACCPAC_OESHDT].[TERRITORY] LIKE '[1-4]','Group A',

IIf([ACCPAC_OESHDT].[TERRITORY] LIKE '[5-7]','Group B',

IIf([ACCPAC_OESHDT].[TERRITORY] LIKE '[89]','Group C','_Unknown Territory')))

HAVING ((SUM(CAST([SAMTSALES] AS MONEY)))>0);

View 7 Replies


ADVERTISEMENT

SQL Server Does Not Exist Or Access Denied - A Real Doozzy And Not Your Standard Problem!!

Sep 26, 2006

Hi ,

I am running SQL Server Desktop Engine on Windows XP. I am developing in .NET framework v1.1.

I intend to u/g to the express edition 2005 however should this old version of the engine be OK (particularly considering that Windows updates are being often run)?

Main question.

For ages the database has worked well then one day recently (just after running a Windows update) the following error occurred SQL Server does not exist or access denied .

I followed my code and this is the result of an exception being thrown in my code due to one of two obvious possibilities.

Everything looks fine as far as SQL Server DEsktop Engine (including services and TCP/IP protocols. Yes I have check cliconf.exe and svrnetcn.exe !!)

I specified mixed mode access (at setup) and In .NET my connection string is :

ConnectionString = "Persist Security Info=false;IntegratedSecurity=sspi;Database=ShedDb;server=warehouse1";

I notice that when I try to login to the database engine with OSQL it does not recognise the original sa password??

Somehow this has been changed (I definitely have not)

Q1. Is it possible that a virus (Worm) could have done this?

Q2. I think that I am stuffed(sorry) because now the sa has changed I cannot perform any admin functions (like resetting the sa pw) Is there any way to change the sa password in this sitatuon?

Q3. The database is locally setup on my development system. When I use the above mentioned connection string I assume that because I do not mention a userid and password that database access is being achieved via Windows authentication (I did specify mixed mode at setup) Is this correct?

Q4. I can appreciate the severity of the sa password being altered. However if Windows authentication is being used by my application, why should this matter? How does Windows authentication work?

Q5. I do have a backup of all the databases including master, model, temp... (I think that the sa password is stored in master). Would the crude approach of simply copying the backup of these backup database files (like master.mdf and master.ldf) suffice in fixing this problem?

Any help would be appreciated.



Thanks

Andrew.

View 8 Replies View Related

Need Help Getting The Day Shift After Midnight

Dec 2, 2006

Hello there,I am having a small problem which been challenging me for few days andneed help or advice.I am trying to calculate the day-shift for employees based on the timethey started and finish working, I will only have 2 shifts 1 or 2 .Shift one changes based on the location however any thing else is shift2. The problem I am having is when someone signed in after midnight; Ineed to report his time under shift 2 for the previous day date. So ifhe signs at 12:30 AM on 12-12-2006, I need to report that as shift 2 on12-11-2006 and that’s where my problem is. Is there a way to subtractthe date by 1. I am using SQL Server and here is a simplified tables Iam working with:Employee tableEmployeID LocationID StartTime EndTime123 555 11:00:00 AM 3:00:00 PM183 559 7:00:00 AM 11:00:00 AM…Shift tableShiftNumber LocationID StartTime EndTime1 555 7:00:00AM 2:00:00PM2 555 2:00:00PM 12:00:00AM1 559 6:00:00AM 4:00:00PM…..So I am trying something likeCASE WHEN (select ShiftNumber FROM Shift WHERE LocationID=TR.LocationIDAND(TR.StartTime>=StartTimeANDTR.EndTime<= EndTime)) =1 THEN 1ELSEWHEN (select ShiftNumber FROM Shift WHERE LocationID=TR.LocationIDAND(TR.StartTime>=StartTimeANDTR.EndTime<= EndTime)) =2 THEN 2ELSE?????????????? NEED HELP HERE WHEN EMPLOYEE SIGN AFTER MIDNIGHTEND)FROMEmployee TRINNER JOIN Shift ON LocationID = TR.LocationID*** Sent via Developersdex http://www.developersdex.com ***

View 3 Replies View Related

Items Centered Or Right Of Center Shift Far Right

Dec 27, 2007

Hello,

I have a BIDS project with 14 reports, all formatted the same way. On one report, any text box or image that is placed in the center or right of center in the form, shifts very far to the right of the tables and charts when it's rendered.



The text box placed at the top left of the form stays put. This is really wierd.

Has anyone ever heard of anything like this.

I have a couple of screen shots if you have a place I can put them.

Thanks

Dan

View 3 Replies View Related

Deciphering Employee Shift Data

Feb 11, 2008

Here is my current challenge that I realize I could do a few different ways but nothing efficient or flexible comes to mind. Hoping one of you guys can help me out with an elequent efficient T-SQL script.

Employee workstate information in our system is stored by segment. Segment 1 cooresponds to the entire shift while segments greater than 1 coorespond to subsequent breaks during the shift (Segment 1). i.e.

SegmentNumber SegmentStart SegmentEnd

1 10:00am 06:00pm
2 12:00pm 13:00pm
3 03:15pm 04:00pm


What I would like to do is generate continuous nonoverlapping records. i.e.

SegmentNumber SegmentStart SegmentEnd

1 10:00am 12:00pm
2 12:00pm 13:00pm
3 13:00pm 03:15pm
4 03:15pm 04:00pm
5 04:00pm 06:00pm


*Notice End has changed to match start of first break and so on. Also records have been added to fill gaps between breaks during the shift.

What adds to the challenge is that the segment number for a given employee/report day can be 1 (meaning no breaks) to any number (lots of breaks). The segment start and end times can be any increment. In addition Breaks can be divided into paid time and unpaid time but I imagine given a solution to the above I could apply it to another level down on my own.

Thank you in advance for your help!

View 3 Replies View Related

SHIFT + SPACE In Table Editor

Feb 6, 2007

The default behaviour for pressing SHIFT + SPACE when editing text inside a cell in the Table Editor view in Microsoft SQL Server Management Studio Express is to change focus to select all cells comprising the current row. This behaviour lends itself to the default behaviour for pressing SHIFT + {LEFT | RIGHT | UP | DOWN } in changing the focus to select adjacent cells.

However, I find this is quite annoying as the SHIFT + SPACE combination is quite a common miss-type when entering text in UpperCaps or when entering text with spaces while holding the SHIFT key.

Anyone else have this gripe with MSSMSE? Anyone know how to disable this behaviour?

Simon

View 2 Replies View Related

Transact SQL :: Identify Shift Which Is Falling To Next Day

May 17, 2015

I have the following shift table:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO

[code]...

I need to identify which shift is currently running on by providing the current time.I used the following query to get the result. It is giving correct result for Morning & Afternoon Shift but failed to produce result for Night Shift.

SELECT ShiftName, Shiftid
FROM WHShifts
WHERE DATEPART(HOUR, @Currenttime)>=(DATEPART(HOUR,CAST(ShiftInTime AS Datetime))) AND DATEPART(HOUR, @Currenttime)<=(DATEPART(HOUR,CAST(ShiftOutTime AS Datetime)))

Is there any way to find out the night shift from a given time.

View 15 Replies View Related

Data Access :: Selecting Data Without Making Any Lock

Oct 26, 2015

I have a scenarios where if I execute select * from tbl it should display the all the records without waiting to release any lock.  For example suppose I have one table called tbl and one session is updating one records and not committed yet and in other session if i execute select * from table I can see all the records, for that records it can show me older version. but my select statement should not wait to commit another session and also it should not show the modified data.

View 4 Replies View Related

Transact SQL :: Calculating Date And Time For 3rd Shift

Jul 13, 2015

We are maintaining 3 Shifts in our database. Problem in maintaining date and time for 3rd Shift. For example, today date is 13th July and third shift timing is 11 PM - 7 AM. Then I have to display the beginning date as 13/07/2015 11 PM and end date as 14/07/2015 7 AM. Please find the data(in seconds) available in database which I need to use for my calculation.

Date(Fcreacion)
Start time in Seconds(Hcreacion)
End time in seconds(Hcerrar)
turno(Shift)

[code]...

View 3 Replies View Related

Transact SQL :: Shift Analysis - CAST Using Times

Nov 9, 2015

I am doing some analysis on shifts and what I want to do is say if the time from a timestamp field is between 00:00 and 05:59 then the figures belong to the day before.  Eg.  We have a night shift that work 22:00 - 06:00.

Here is my coding which logically looks sound to me but when I run it, it has an error:

SELECTe.ID,
CAST(e.TimestampasDate)asEventDate,
CAST(e.TimestampasTime)asEventTime,
CASE
WHENCAST(e.TimestampasTime)BETWEEN'00:00:01'and'05:59:59'
THENCAST(e.TimestampasDate)-1
ELSECAST(e.TimestampasDate)
END
FROMIntouch.Event

View 5 Replies View Related

Grouping By Custom Datepart For Shift Patterns

Apr 27, 2006

My application has a log table with a timestamp field which represents the time when the record was inserted.

We would like query the the table and group the results into date units based on the value of the timestamp.

The grouping specification is held in another table but only specified for a single week.

For example

WeekDay Start End

1 06:00:00 14:00:00

2 08:10:00 17:00:00

What this specification means is that when the log table is queried records with a timestamp that fall on a Monday between 06:00:00 and 14:00:00 should be grouped together, on Tuesday the group is records between 08:10:00 and 17:00:00 and so on...

The only way I can think of doing this is to generate a temporary table when the log table is queried that has a unique record for each time period for the span of the query and then attempt to join this table to the log table using the timestamp and then group based on the temporary table unique ID.

I'm not sure how to generate such a temporary table from the specification table so any help would be appreciated.



Thanks in advance.

View 5 Replies View Related

How To Display Unicode Data Stored In MSSQL As Shift-jis In ASP

Nov 22, 2006

 We are experiencing problems in presenting Unicode data stored in MSSQL as Shift-jis format in ASP application.
In MSSQL we are storing kanji text in database with a field type as nchar. Other application loads these tables using codepage 932. In MSSQL data is stored in Kanji correctly.
In ASP application, when we are trying to read data from these tables, Kanji characters are coming as '?????'. We are using shift-jis character set in ASP.
Templates for field and column header uses shift-jis, but a record set coming from MSSql is Unicode.
Is there a  way to convert from Unicode to Shift-jis in MSSql or in ASP .
Please help!!

View 1 Replies View Related

Report Objects Shift To Right On Very Wide Report - Why?

Mar 13, 2007

Greetings,

I have a very wide report of more than 20 inches. I've placed several parameter values in the report header section so that the user can see what filters have been applied to the data. The testboxes shift their position several inches to the right when the report is run from the Report Manager.

Is there a way to make sure that a textbox is displayed at an absolute position? I thought maybe there would be a property on the report or body object that controls this but I don't see one.

Thanks for your help,

BCB

View 7 Replies View Related

Can Someone Help With This T-SQL Real Quick?

Nov 11, 2007

Hey guys... i cant figure this out for the life of me.  I have a long T-sql query, and when i enter the string "Rental" into the Listingtype, it says invalid column name "Rental" ... im not looking for the value to be a column, im looking for it to match the value in the ListingType column... here's the query:
 
 (

@StudioINT = NULL,
@Br1INT = NULL,
@Br2INT = NULL,
@Br3INT = NULL,
@Br4INT = NULL,
@OverBr4INT = NULL,
@CondoINT = NULL,
@ListingTypevarchar(10) = NULL,
@WindowAirINT = NULL,
@CentralACINT = NULL,
@BalconyDeckPatioINT = NULL,
@UseOfYardINT = NULL,
@DishwasherINT = NULL,
@WasherDryerINT = NULL,
@FireplaceINT = NULL,
@EIKINT = NULL,
@HardwoodFloorsINT = NULL,
@BroadbandNetINT = NULL,
@TVINT = NULL,
@ThermostatINT = NULL,
@LandlordNotPresentINT = NULL,
@SmokingINT = NULL,
@NoPetsAllowedINT = NULL,
@CatINT = NULL,
@MoreCatsINT = NULL,
@SmallDogINT = NULL,
@LargeDogsINT = NULL,
@DoorpersonINT = NULL,
@IngroundPoolINT = NULL,
@AboveGroundPoolINT = NULL,
@ElevatorINT = NULL,
@UseOfGarageINT = NULL,
@LaundryFacilitiesINT = NULL,
@HealthCenterINT = NULL,
@StorageAreasINT = NULL,
@WheelchairAccessINT = NULL,
@BusinessCentersINT = NULL,
@RentChargeMinINT = NULL,
@RentChargeMaxINT = NULL,
@DebugBIT = 1
)
AS

SET NOCOUNT ON

DECLARE @SQL VARCHAR(8000)

SET @SQL = '
SELECT

r.REListingID,
r.REListingDate,
r.Username,
r.ZipCode,
r.ListingType,
r.StudioFlag,
r.BRFlag1,
r.BRFlag2,
r.BRFlag3,
r.BRFlag4,
r.OverBRFlag4,
r.CondoFlag,
a.WindowAir,
a.CentralAir,
a.BalconyDeckPatio,
a.UseOfYard,
a.Dishwasher,
a.WasherDryer,
a.Fireplace,
a.EIK,
a.HardwoodFloors,
a.BroadbandNet,
a.TV,
a.Thermostat,
a.LandlordNotPresent,
a.Smoking,
a.NoPetsAllowed,
a.Cat,
a.MoreCats,
a.SmallDog,
a.LargeDogs,
a.Doorperson,
a.IngroundPool,
a.AboveGroundPool,
a.Elevator,
a.UseOfGarage,
a.LaundryFacilities,
a.HealthCenter,
a.StorageAreas,
a.WheelchairAccess,
a.BusinessCenters,
a.RentCharge,
a.RentFrequency
FROMdb_REListings as r
INNER JOINdb_RentalAmenities AS a ON a.REListingID = r.REListingID
WHERE1 = 1
'

IF @Studio IS NOT NULL
SET @SQL = @SQL + ' AND r.StudioFlag = ' + CONVERT(VARCHAR(20), @Studio)
IF @Br1 IS NOT NULL
SET @SQL = @SQL + ' AND r.BRFlag1 = ' + CONVERT(VARCHAR(20), @Br1)
IF @Br2 IS NOT NULL
SET @SQL = @SQL + ' AND r.BRFlag2 = ' + CONVERT(VARCHAR(20), @Br2)
IF @Br3 IS NOT NULL
SET @SQL = @SQL + ' AND r.BRFlag3 = ' + CONVERT(VARCHAR(20), @Br3)
IF @Br4 IS NOT NULL
SET @SQL = @SQL + ' AND r.BRFlag4 = ' + CONVERT(VARCHAR(20), @Br4)
IF @OverBr4 IS NOT NULL
SET @SQL = @SQL + ' AND r.OverBRFlag4 = ' + CONVERT(VARCHAR(20), @OverBr4)
IF @Condo IS NOT NULL
SET @SQL = @SQL + ' AND r.CondoFlag = ' + CONVERT(VARCHAR(20), @Condo)
IF @ListingType IS NOT NULL
SET @SQL = @SQL + ' AND r.ListingType = ' + CONVERT(char, @ListingType)
IF @WindowAir IS NOT NULL
SET @SQL = @SQL + ' AND a.WindowAir = ' + CONVERT(VARCHAR(20), @WindowAir)
IF @CentralAC IS NOT NULL
SET @SQL = @SQL + ' AND a.CentralAir = ' + CONVERT(VARCHAR(20), @CentralAC)
IF @BalconyDeckPatio IS NOT NULL
SET @SQL = @SQL + ' AND a.BalconyDeckPatio = ' + CONVERT(VARCHAR(20), @BalconyDeckPatio)
IF @UseOfYard IS NOT NULL
SET @SQL = @SQL + ' AND a.UseOfYard = ' + CONVERT(VARCHAR(20), @UseOfYard)
IF @Dishwasher IS NOT NULL
SET @SQL = @SQL + ' AND a.Dishwasher = ' + CONVERT(VARCHAR(20), @Dishwasher)
IF @WasherDryer IS NOT NULL
SET @SQL = @SQL + ' AND a.WasherDryer = ' + CONVERT(VARCHAR(20), @WasherDryer)
IF @Fireplace IS NOT NULL
SET @SQL = @SQL + ' AND a.Fireplace = ' + CONVERT(VARCHAR(20), @Fireplace)
IF @EIK IS NOT NULL
SET @SQL = @SQL + ' AND a.EIK = ' + CONVERT(VARCHAR(20), @EIK)
IF @HardwoodFloors IS NOT NULL
SET @SQL = @SQL + ' AND a.HardwoodFloors = ' + CONVERT(VARCHAR(20), @HardwoodFloors)
IF @BroadBandNet IS NOT NULL
SET @SQL = @SQL + ' AND a.BroadbandNet = ' + CONVERT(VARCHAR(20), @BroadbandNet)
IF @TV IS NOT NULL
SET @SQL = @SQL + ' AND a.TV = ' + CONVERT(VARCHAR(20), @TV)
IF @Thermostat IS NOT NULL
SET @SQL = @SQL + ' AND a.Thermostat = ' + CONVERT(VARCHAR(20), @Thermostat)
IF @LandlordNotPresent IS NOT NULL
SET @SQL = @SQL + ' AND a.LandLordNotPresent = ' + CONVERT(VARCHAR(20), @LandLordNotPresent)
IF @Smoking IS NOT NULL
SET @SQL = @SQL + ' AND a.Smoking = ' + CONVERT(VARCHAR(20), @Smoking)
IF @NoPetsAllowed IS NOT NULL
SET @SQL = @SQL + ' AND a.NoPetsAllowed = ' + CONVERT(VARCHAR(20), @NoPetsAllowed)
IF @Cat IS NOT NULL
SET @SQL = @SQL + ' AND a.Cat = ' + CONVERT(VARCHAR(20), @Cat)
IF @MoreCats IS NOT NULL
SET @SQL = @SQL + ' AND a.MoreCats = ' + CONVERT(VARCHAR(20), @MoreCats)
IF @SmallDog IS NOT NULL
SET @SQL = @SQL + ' AND a.SmallDog = ' + CONVERT(VARCHAR(20), @SmallDog)
IF @LargeDogs IS NOT NULL
SET @SQL = @SQL + ' AND a.LargeDogs = ' + CONVERT(VARCHAR(20), @LargeDogs)
IF @Doorperson IS NOT NULL
SET @SQL = @SQL + ' AND a.Doorperson = ' + CONVERT(VARCHAR(20), @Doorperson)
IF @IngroundPool IS NOT NULL
SET @SQL = @SQL + ' AND a.IngroundPool = ' + CONVERT(VARCHAR(20), @IngroundPool)
IF @AboveGroundPool IS NOT NULL
SET @SQL = @SQL + ' AND a.AboveGroundPool = ' + CONVERT(VARCHAR(20), @AboveGroundPool)
IF @Elevator IS NOT NULL
SET @SQL = @SQL + ' AND a.Elevator = ' + CONVERT(VARCHAR(20), @Elevator)
IF @UseOfGarage IS NOT NULL
SET @SQL = @SQL + ' AND a.UseOfGarage = ' + CONVERT(VARCHAR(20), @UseOfGarage)
IF @LaundryFacilities IS NOT NULL
SET @SQL = @SQL + ' AND a.LaundryFacilities = ' + CONVERT(VARCHAR(20), @LaundryFacilities)
IF @HealthCenter IS NOT NULL
SET @SQL = @SQL + ' AND a.Health Center = ' + CONVERT(VARCHAR(20), @HealthCenter)
IF @StorageAreas IS NOT NULL
SET @SQL = @SQL + ' AND a.StorageAreas = ' + CONVERT(VARCHAR(20), @StorageAreas)
IF @WheelchairAccess IS NOT NULL
SET @SQL = @SQL + ' AND a.WheelchairAccess = ' + CONVERT(VARCHAR(20), @WheelchairAccess)
IF @BusinessCenters IS NOT NULL
SET @SQL = @SQL + ' AND a.BusinessCenters = ' + CONVERT(VARCHAR(20), @BusinessCenters)
IF @RentChargeMin IS NOT NULL AND @RentChargeMAX IS NOT NULL
SET @SQL = @SQL + ' AND a.RentCharge BETWEEN ' + CONVERT(VARCHAR(20), @RentChargeMin) + ' AND ' + CONVERT(VARCHAR(20), @RentChargeMax)
IF @RentChargeMin IS NOT NULL AND @RentChargeMAX IS NULL
SET @SQL = @SQL + ' AND a.RentCharge >= ' + CONVERT(VARCHAR(20), @RentChargeMin)
IF @RentChargeMAX IS NULL AND @RentChargeMAX IS NOT NULL
SET @SQL = @SQL + ' AND a.RentCharge <= ' + CONVERT(VARCHAR(20), @RentChargeMax)

IF @Debug = 1
PRINT @SQL

EXEC (@SQL) 

View 5 Replies View Related

Newbie Needs Real Help

Feb 14, 2001

Hi. I am trying to setup php4 to talk to MSSQL 7, but am having no luck. Both are on a Win2k server. I get the error below. Please can someone tell me what to do, or even a step by step guide to setting up php to connect to a MSSQL7 database. I originally created the database in access 2000 and now want to use MSSQL to use it. This is the error i get:

Warning: MS SQL message: Could not locate entry in sysdatabases for database 'customers'. No entry found with that name. Make sure that the name is entered correctly. (severity 16) in C:Websiteewsiteestdb.php on line 13

Warning: MS SQL: Unable to select database: customers in C:Websiteewsiteestdb.php on line 13
Database unavailable

View 2 Replies View Related

The REAL Problem

Oct 3, 2000

I was running a server with TempDB in RAM (please don't comment on why that's not a good idea). Well, everything was fine until one of our administrator install teh backup exec agent and restarted the server. Since then the server won't start giving an error the Tempdb coulld not be moved into ram. Well, I started the server using the -f parameter and reset the Tempdb in RAM setting to zero. Howeever, it still won't start and gives the same error about not being able to move Tempdb into RAM. Is my only option to rebuild the master database? This is just a backup server but I'd like to avoid the hassle of rebuilding master and reinitializing the databases.


--Buddy

View 4 Replies View Related

A Real SQL Mindblower

May 18, 2004

Hi,

I'm trying to work out how to extract the information that I need from a set of database tables and can't think of a way of doing it with SQL.

The database forms the basis for a diary/calendar system for part-time employees and has two tables:

- One is called 'Availability' and holds info on each available hour slot in the calendar. The table just has fields 'time' and 'date', where the time is an integer representing an hour and date is datetime. The calendar runs from 07.00 to 23.00 each day, so there could be 16 rows in 'Availability' for one day. If any part of a day is unavailable (i.e. the employee doesn't work then) there will be no corresponding rows in the table.

- The second table is 'Appointments', which holds details of appointments that the employee is booked for. The main fields are 'date', 'time' and 'duration' (integer for minutes). All appointments will cover a time span that is also covered by an available period, but they are not actually linked in any way.

I need an SQL query that will return all available time slots that start at least 60 minutes after any appointments have FINISHED and at least 120 minutes before any appointment STARTS.

Since there is no link between the 'Appointments' table and the 'Availability' table, I can't think of any way of doing this.

Any ideas?

View 8 Replies View Related

Real To Datetime - How To...?

Mar 5, 2007

Hi,I would like to convert real data type to datetime type. Example:I have a real data type which is: 23,613456 (23 hours and 0,613456). Iwould like to have it in hh:mm:ss format. How to do this? Can I useconvert/cas function?Thanks for helpRgdsMario

View 1 Replies View Related

Finding If A REAL Is LIKE '%[49]9'

Jul 20, 2005

Timings... sometimes there are almost too many ways to do the same thing.The only significant findings I see from all the below timings is:1) Integer math is generally fastest, naturally. Bigint math isn't muchslower, for integers that all fit within an integer.2) Converting float to varchar is relatively slow, and should be avoided ifpossible. Converting from integer to varchar or varchar to int is severaltimes faster.3) Most significantly, and less obvious, CASE expr WHEN .... recomputes exprfor each WHEN condition, unfortunately, and is the same speed (or perhapsslightly slower) as listing WHEN expr = value for each condition. Perhaps anindexed computed column (somehow materialized) would be advisable whenpossible to avoid repeated computations in CASE..WHEN expressions (if thathelps..).Note that if you divide by COUNT(*), most timings below are below onemicrosecond per row, so this all may not be very significant in mostapplications, unless you do frequent aggregations of some sort.COUNT(*) FROM [my_sf_table] = 477446 rowsThe result from each query = either 47527 or 47527.0Platform: Athlon 2000 XP w/512MB RAM, table seems to be cached in RAM, SQL2000, all queries run at least 3 times and minimum timings shown (msec).SRP is a REAL (4 bytes)Fastest ones are near the end.CPU SQL(ms)-- Convert to varchar (implicitly) and compare right two digits-- (original version -- no I didn't write it)4546 select sum(case right(srp,2)when '99' then 1 when '49' then 1 else 0 end)from sf-- Use LIKE for a single comparison instead of two, much faster-- Note that the big speedup indicates that-- CASE expr WHEN y then a WHEN z then b .-- recalculates expr for each WHEN clause2023 select sum(case when srp like '%[49]9' then 1 else 0 end)from sf-- Floating point method of taking a modulus (lacking fmod/modf)2291 select sum(case round(srp - 100e*floor(srp*.01e),0)when 99 then 1 when 49 then 1 else 0 end)from sf-- Round to nearest 50 and compare with 491322 select sum(case round(srp-50e*floor(srp*.02e),0)when 49 then 1 else 0 end)from sf-- Divide by 49 by multiplying by (slightly larger than) 1e/49e811 select sum(floor((cast(srp as integer)%50)*2.04082E-2))from sf-- Integer approach without using CASE731 select sum(coalesce(nullif(sign(cast(srp asinteger)%50-48),-1),0))from sf-- My original integer approach651 select sum(case cast(srp as integer)%100when 99 then 1 when 49 then 1 else 0 end)from sf-- Modulus 50 integer approach without CASE481 select sum((cast(srp as integer)%50)/49)from sf-- Modulus 50 integer approach460 select sum(case cast(srp as integer)%50when 49 then 1 else 0 end)from sf-- bigint without CASE531 select sum((cast(srp as bigint)%50)/49)from sf-- bigint with CASE521 select sum(case cast(srp as bigint)%50when 49 then 1 else 0 end)from sf-- get SIGN to return -1 or 0, then add 1-- much better than the coalesce+nullif approach500 select sum(sign(cast(srp as integer)%50-49)+1)from sf-- SIGN with BIGINT551 select sum(sign(cast(srp as bigint)%50-49)+1)from sfBTW, I know srp should be int to begin with for this to be faster... Okay,so...select cast(srp as int) srp into sf from [my_real_sf_table]720 select sum(case when srp like '%[49]9' then 1 else 0 end) from sf339 select sum(1+sign(srp%50-49)) from sf310 select sum(srp%50/49) from sf300 select sum(case srp%50 when 49 then 1 else 0 end) from sfWhat if it were a char(7)?select cast(cast(srp as integer) as char(7)) srp into sf2 from[my_sf_table]801 select sum(case right(rtrim(srp),2) when '49' then 1when '99' then 1 else 0 end) from sf2717 select sum(case when srp like '%[49]9' then 1 else 0 end) from sf2405 select sum(srp%50/49) from sf2391 select sum(case srp%50 when 49 then 1 else 0 end) from sf2How about varchar(7)?drop table sf2select cast(cast(srp as integer) as varchar(7)) srp into sf2 from[my_sf_table]581 select sum(case right(srp,2) when '49' then 1when '99' then 1 else 0 end) from sf2569 select sum(case when srp like '%[49]9' then 1 else 0 end) from sf2LIKE is faster on VARCHAR than on CHAR columns...Apparently it has to effectively RTRIM the trailing spaces during the LIKEoperation.Is binary collation any faster?drop table sf2select cast(cast(srp as integer) as varchar(7))COLLATE Latin1_General_BIN srpinto sf2 from tbl_superfile561 select sum(case right(srp,2) when '49' then 1when '99' then 1 else 0 end) from sf2530 select sum(case when srp like '%[49]9' then 1 else 0 end) from sf2Binary collation comparisons are slightly faster, though it's not a bigdifference (with just two characters being compared).662 select sum(case convert(binary(2),right(srp,2))when 0x3439 then 1 when 0x3939 then 1 else 0 end) from sf2-----------5037 select right(srp,2) srp,count(*) from my_sf_tablegroup by right(srp,2)order by right(srp,2)920 select cast(srp as int)%100 srp,count(*) from my_sf_tablegroup by cast(srp as int)%100order by cast(srp as int)%100---On the one hand, premature optimization can be a waste of time and energy.On the other hand, understanding performance implications of variousoperations can help write more efficient systems.In any case, an indexed computed column or one updated on a trigger couldvirtually eliminate the need for any of these calculations to be performed,except upon insertion or update, so maybe my comparisons aren't verymeaningful for most applications, considering we're talking about less than3 microseconds per row here worst-case.But the results remind me, some recommend avoiding Identity when it's notnecessary. I find Identity(int,1,1) to be a nice, compact surrogate key thatis useful for quick comparisons, grouping, etc, and so on. Also, it seemsmost appropriate as the primary key to all lookup tables in a star schema inOLAP data warehousing. (?) Of course, in some situations, it's notappropriate, particularly when having a surrogate key violates dataintegrity by allowing duplicates that would not be allowed with a properprimary key constraint, or when the surrogate key is completely redundantwith (especially a short) single-column unique key value that would be abetter selection as the primary key. With multi-column primary keys, I thinkit's sometimes convenient to have a surrogate Identity if only for INclauses that reference that identity column (though EXISTS can usuallyreplace those, so maybe that's a weak excuse for an extra column.)

View 4 Replies View Related

How Does The Real SQL String Look Like?

Aug 22, 2007

Hello,

I define the sql-query:

SELECT myColumn FROM myPersonsTable WHERE myColumn=@FirstName

then I declare some SqlParameters like:

SqlParameter par=new SqlParameter();
par.ParameterName="@FirstName";
par.Value="John";
mySqlCommand.Parameters.Add(par);

Showing the mySqlCommand.CommandString it will look like:
(A) SELECT myColumn FROM myPersonsTable WHERE myColumn=@FirstName
Is this the real string that is send to the Database (among with some hidden string "John")?...

...or does the real string which is send to the Database look like:
(B) SELECT myColumn FROM myPersonsTable WHERE myColumn='John'
???

If so, where can I retrieve that last string (B)?
Or is (A) the way 'transact sql' operates?

Henk

View 3 Replies View Related

Sa Real Login Name

Nov 8, 2006

Greetings,

I have a SQL Server 2000 database using Integrated Security. Users are added directly to the database from their domain name. In the Login section of the Security node in Enterprise Manager they show up as DomainNameUserName. I have four users that have the System Administrator database role. When I use the user function to get their user name they show up as dbo. Is there a way to get their actual domain user name?

Thanks.

View 3 Replies View Related

Help For A Real Newbie

Oct 23, 2006

A problem so simple I'm a little embarrassed to post it... I am setting up a trigger in which I want to, among other things, record the network ID of the user who performs the action that triggers the trigger. I know there is a variable or function out there to pull that information, but I can't find it, and have tried every variation of "login logname usr_id network_id....." I can find.

So first.... could somebody please tell me the variable or function that will return that piece of information. And second, if you also could point me to a good place, either in print or on line, to look up that kind of information, I would be most grateful.



Thanks.

View 2 Replies View Related

Real Newbie Post...

Sep 1, 2006

I was hoping there would be a newbie section in here... But I'll post anyway (And sorry in advance if its a really dumb question)I am using VWDE and have a SQL DB which has been imported from one of my existing forums, when it shows in the database explorer its show like belowtblArcade (jdName)tblArcadePB (jdName)etc..etc...What I want to know is why this DB has (jdName) after the Table name and my other DB's shown don't?? They are just shown as tblArcade
tblArcadePB etc..etc.. My main questions are "How do I remove the brackets from the forum DB" as when I try to preview data in VWDE I get a message Invalid object name 'tblArcade'.I know its to do with this extra bit as it only happens to the tables that have this on the end... Hope that makes sense and someone can help me, if you could reply as if I'm really dumb it would be appreciated  

View 4 Replies View Related

Real Time Data

Jan 25, 2007

I currently have an application which retrieves stats from a SQL database that are updated throughout the day. My application updates every 3 seconds to retrieve these stats but I found that it's quite expensive to the server's CPU when there are several clients running my application. Are there any other methods for extracting the data that won't require so much CPU. The fact that the database is being hit so much isn't good either. I have already written a webservice hoping that this would improve things but I'm not sure it has.

View 3 Replies View Related

Get Real XML Execution Plan

Jul 9, 2007

 Hi,I want to access the real execution plan via my webapplication after I have executed an SQL statement. I know how to get the estimated execution plan:1 cmd.CommandText = "SET SHOWPLAN_XML ON";2 cmd.ExecuteNonQuery();3 4 cmd.CommandText = myStatement;5 SqlDataReader dataReader = cmd.ExecuteReader();6 7 String plan = String.Empty;8 9 while (dataReader.Read()) {10 plan += dataReader.GetSqlString(0).ToString();11 }12 13 cmd.CommandText = "SET SHOWPLAN_XML OFF";14 cmd.ExecuteNonQuery();I want do compare the estimated costs with the real costs of the same statement. If I change code line 1 an 13 to "SET STATISTICS XML [ON|OFF]" the string "plan" will contain the result of the submitted SELECT statement, but I just need to get the plan and not the result itself. Thanks in Advance,Dominik 

View 6 Replies View Related

Diff Between Float And Real

Jan 7, 2008

Hi All,
What is the difference betwen real and float datatype of SQL  server.
Please one exapmle for each.
The  real datatype is like a float except  that real can only store numbers.What does it mean: float can store even characters.
Thanks
Abdul
 
 
 

View 2 Replies View Related

Real Beginner's Question

Aug 11, 2005

I have a datagrid that is used to insert values into a table. Before
the insert occurs I want to be able to check that there are no
identical values already in the table. eg. I am inserting names, so am
looking for last name duplicates only.

If a duplicate is found, it should return an error message to the page.
My question is, can I do this duplicate checking via SQL script ie. IF
EXISTS etc... and have the error message returned from there, or do I
need to grab a dataset of the table and look for duplicates before even
going as far as  the database with the new value to be inerted?

If the best approach is to catch the duplicate error after executing
the SQL script, how do I grab the error and return it to the page with
the datagrid? I'm sure this is pretty basic, but I am only just now
getting into it.

SQL Server 2000 is being used here.

Thanks!

View 1 Replies View Related

SQL Real Time Replication

May 6, 2001

We are using SQL 7 at 2 different locations, on 2 different Domains that are connected via a T1 line.

We need to have our 2 SQL servers be identical at all times, meaning when a change is made on one server, it is immediately replicated to the other. The problem is that both servers are always being used, so there is no primary/backup server scenario.

Does anyone know if there is a third party software available, or if this is even possible to do, given the fact that the databases are always open ?

Thanks.

View 1 Replies View Related

Real Time Synchronisation

Oct 24, 2000

Hello,

Can anyone guide me. which is the best method for real time synchronisation of my production server. Is it Transactional Replication or Stand By Server?

Thanks In Advance

Sejal

View 2 Replies View Related

REAL CHALLENGE For The Smart One

May 8, 2002

Hi,
tell me please how I can trace the modification on the table such as "insert" record into one and syncronize mirror table at the same time once the insert has happend, BUT - no indexes no trace jobs, no any modification or objects on the master table... ha?

View 5 Replies View Related

Cast Real To Money

Dec 26, 2014

When I cast Real to Money it makes some changes to the number

DECLARE @i REAL = 989500000.00;

SELECT CAST(@i AS MONEY)
the result is : 989500032.00

what should I do for stop this ?

View 2 Replies View Related

Real Time Replication

Apr 24, 2008

I have two database, one is for production and another for reporting database, in this Scenario we need to transfer the real time data to reporting database, which replication we need to use and what at the bottelnecks in this..can any one give some suggesstions or give some links...

Thanks in advance

View 4 Replies View Related

Real Work Get Paid

Jul 26, 2006

(Spam Removed.)

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved