I need to query data from a table which has order_date which is datetime field. How to pull orders by hour by day per month for the last 4 months. Any idea how to write the query?
if now the system time is 2014-12-23 23:45:345 . then I want to calculate the sales amount with total and get current date and current hour filter by hh:00-hh:59 , my desire output is like below :
Current time:23:50 run this query Date Time amount 2014-12-23 23:40 $10 2014-12-23 23:01 $5 2014-12-23 23:39 $5 Total :$20
Time Interval for hour and 30 minutes --------------------------------------------------------------------------------
Hi Everyone
I Have column in sql server databas as "HHMMSS" and data as and i am doing a substring to get values for hours and minutes. since my calculations based on hour interval and 30 minutes interval
for ex: Now i want to show all the transaction done b/w 6 to 7 am or pn.
and for 30 minutes interval i have get the calculation as transactions done b/w 6:00 to 6:30 and 6:30 to 7:00 either it's am or pm. now how i can write my sql statements that calculates hour and 30 minutes intervals HHMM ------------- 06:43 09:26 09:26 11:58 12:25 18:17 20:45 00:43 00:53 16:47
I need to convert the given time into 24 hour clock .
I have the two tables out of which one contain time in 12 Hr clock and another contain time in 24 Hr clock and i need to make a join on this colum by converting 12 Hr time in to 24 hr clock time.
ID Date Time Length Interval_Num 1 10/11/2014 9:00 420 14
Basically, length represents the # of minutes a person is scheduled for. We have 30 minute intervals. Interval_Num = (Length/30). I need the data to show each interval. For the above example it should only be 14 intervals.For the above example the solution should look like....
ID Date Time Length 1 10/11/2014 9:00 30 1 10/11/2014 9:30 30 1 10/11/2014 10:00 30 1 10/11/2014 10:30 30
I would like to make a function to convert a datetime to half-hour. E.g. If the timestamp is 1:23:05 then converts to 1:30:00, if 1:35:27 then converts to 2:00:00.
SSRS 2008 R2. I am writing a report that uses a DB4 database. Because of this many SQL commands that I normally use are not available and I don't know what commands I can use. Because of this I am doing much of my calculations inside of SSRS.
I need to round a time field to the nearest quarter hour inside of SSRS.
i need to be able to do an sql call whereby i can check the day and hour for publishing.eg select story where day = ?? AND hour = ?? any one know the best way to do this. i need to call out date as a day number or someting and the getdate as just the hour??? anyone know how??
I know how to do this in Excel, but not sure about Power Pivot. Our fire department works on a 24 hour shift that starts at 0700 each morning. I want to look up what shift is working depending on the date and time of dispatch. In Excel, I would do a look up table, but instead of using false() as the last parameter, I would choose true().
I am not sure if this would be best created as a calculated column in the table that holds the incident date and time values, or have a separate table and create a relationship to use the shift in the rows/columns of my pivot table.
I need to take a temporary table that has various times stored in a text field (4:30 pm, 11:00 am, 5:30 pm, etc.), convert it to miltary time then cast it as an integer with an update statement kind of like:
Update myTable set MovieTime = REPLACE(CONVERT(CHAR(5),GETDATE(),108), ':', '')
how this can be done while my temp table is in session?
In this query I select from a column that contains numbers, the result I want is a varchar that is always 2 chars wide..
Ie: 7 should be selected as '07' 12 should be selected as '12'
In the Access-query it's rather nicely done with: Format(Str(mycolumn),"00")
I could not find a way to make CONVERT do the same job... but I found that: LEFT('00',2-LEN(CAST(mycolumn as varchar)))+CAST(mycolumn as varchar) will do the job.
But it feels like it could be done nicer.. any suggestions?
Hi, I am trying ot do a count with a clause like this "amtdue >=10000 and amtdue <=25000" --- I get and error that says "Syntax error converting the varchar value '52.91' to a column of data type int" There are 20 million records in the table - this field is formatted as a varchar - can someone help me find the problem?
I am struggling with converting a certain varchar column into an int.I have a table that has 2 fields - one field holds the loan number andthe other field holds the codes associated with that loan number.Here's some example data:Loan# Codes11111 24-13-122222 133333 2-9I need to check the Codes field for certain code numbers. The Selectstatement I'd like to use is:SELECT Loan#FROM Table1 WHERE Codes IN (2, 13, 1)/*My desired results is that all loans from the above example would beselected because they all have one of these codes*/Of course I cannot use the above statement because the Codes field is avarchar. And if I put single quotes around the numbers in my INstatement I don't get the desired results; the fields with multiplecodes are excluded.But how do I convert this varchar to an int? A simple convert or caststatement doesn't work. I've looked all over the web to find how to dothis, but have not been able to figure it out. Any help would be muchappreciated.
I wrote a query that takes the field from one record and compares it to a different field in a different record. When I did it in access it worked. But I did a copie and paste into management studio and it is not working.
SELECT A.TRAN_ID, B.REFERENCE_DATA FROM dbo.BSTRN_HEADER AS B LEFT OUTER JOIN dbo.BSTRN_HEADER AS A ON B.REFERENCE_DATA LIKE A.TRAN_ID &'RECL'
I get the following error message:
Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value 'RECL' to data type int.
So then I try:
SELECT A.TRAN_ID, B.REFERENCE_DATA FROM dbo.BSTRN_HEADER AS B LEFT OUTER JOIN dbo.BSTRN_HEADER AS A ON B.REFERENCE_DATA LIKE cast(A.TRAN_ID as varchar) & 'RECL'
I get the following error Msg 402, Level 16, State 1, Line 1 The data types varchar and varchar are incompatible in the boolean AND operator.
Tran_id is an integer and reference data is a varchar and I need to convert tran_id to a Varchar
I have a password field which is of varbinary. Since its a varbinary I cannot see the password in the database I only see hexadecimal values. Now my question is that how can I convert those hexadecimal values to string or varchar so I can read the password.
Is it possible to convert from ntext to varchar or text?? This is the syntax: ALTER TABLE ssu ALTER COLUMN analysis varchar NULL. This is the error message Server: Msg 4928, Level 16, State 1, Line 1 Cannot alter column 'ANALYSIS' because it is 'ntext'. Thanks in advance!
Hi I have a table named prodwin in which i have to update a column name mfgdt which is varchar(10) to 7 months which I am able to do but the problem is that since it is only 10 character it is cutting the end of the year for eg
Before the date was 5/22/2000
UPDATE PRODWIN_MM SET MFGDT = DATEADD(MM,7,MFGDT)
Now it is this
Dec 23 200
Please tell me what to do , should i use cast or convert ?
I'm facing a small issue with date conversions. It would have been great if someone could help me out. I have a field in my database (SQL Server 2000) called SavDateTime of type varchar(50). I store dates in this field in the format "dd/MM/yy hh:mms". A sample date would be "23/10/2007 10:15:30 AM". Now I need to have an order by for this field, say like,
select * from sample order by SavDateTime desc
When I execute this query I get an error saying "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.". I tried using the convert method also like CONVERT(DATETIME,SavDateTime,103), but the problem still exists. It would have been helpful if you could provide me with a solution to this problem.
why do i have this error? not converting a varchar into int 1 ALTER PROCEDURE dbo.RevertDB 2 ( 3 @Log varchar(MAX) = NULL OUTPUT 4 ) 5 6 /* Reverts Database to original "Clean" State */ 7 AS 8 SET NOCOUNT OFF 9 DECLARE @RowsInDB AS int 10 SET @Log = 'RevertDB Started at ' + CAST(GETDATE() AS varchar(50)) + '<br />' 11 12 /* *** Disable Constraints *** 13 ALTER TABLE Booking NOCHECK CONSTRAINT ALL 14 ALTER TABLE InventoryPC NOCHECK CONSTRAINT ALL 15 ALTER TABLE PC NOCHECK CONSTRAINT ALL 16 ALTER TABLE Platform NOCHECK CONSTRAINT ALL*/ 17 18 /* *** Start Deletes *** */ 19 DELETE FROM Booking 20 SET @Log = @Log + 'Clear Table Booking - Done' + '<br />' 21 SET @RowsInDB = (SELECT COUNT(BookingID) FROM Booking) 22 SET @Log = @Log + '-- Rows Affected: ' + CAST(@@ROWCOUNT AS varchar(10)) + ', Rows in Table: ' + CAST(@RowsInDB AS varchar(10)) + '<br />' 23 24 DELETE FROM InventoryPC 25 SET @Log = @Log + 'Clear Table InventoryPC - Done' + '' 26 SET @RowsInDB = (SELECT COUNT(InventoryID) FROM InventoryPC) 27 SET @Log = @Log + '-- Rows Affected: ' + CAST(@@ROWCOUNT AS varchar(10)) + ', Rows in Table: ' + CAST(@RowsInDB AS varchar(10)) + '<br />' 28 29 DELETE FROM PC 30 SET @Log = @Log + 'Clear Table PC - Done' + '<br />' 31 SET @RowsInDB = (SELECT COUNT(PCID) FROM PC) 32 SET @Log = @Log + '-- Rows Affected: ' + CAST(@@ROWCOUNT AS varchar(10)) + ', Rows in Table: ' + CAST(@RowsInDB AS varchar(10)) + '<br />' 33 34 DELETE FROM Platform 35 SET @Log = @Log + 'CLear Table Platform - Done' + '' 36 SET @RowsInDB = (SELECT COUNT(PlatformID) FROM Platform) 37 SET @Log = @Log + '-- Rows Affected: ' + CAST(@@ROWCOUNT AS varchar) + ', Rows in Table: ' + CAST(@RowsInDB AS varchar(10)) + '<br />' 38 39 /* *** Enable Constraints *** 40 ALTER TABLE Booking WITH CHECK CHECK CONSTRAINT ALL 41 ALTER TABLE InventoryPC WITH CHECK CHECK CONSTRAINT ALL 42 ALTER TABLE PC WITH CHECK CHECK CONSTRAINT ALL 43 ALTER TABLE Platform WITH CHECK CHECK CONSTRAINT ALL*/ 44 45 SET @Log = @Log + '*** End Truncates ***' + '<br />' 46 /* *** End Truncates *** */ 47 48 /* *** Start Insert Platform *** */ 49 SET @Log = @Log + 'Start Insert Platform' + '<br />' 50 51 EXEC dbo.InsertPlatfrom 'Windows XP SP2 Professional Edition', 'Some description for Windows XP SP2 Professional Edition over here …' 52 EXEC dbo.InsertPlatfrom 'Windows Vista Ultimate', 'See everything you''re working on more clearly with Windows Aero, and quickly switch between windows or tasks using Windows Flip 3D and Live Thumbnails. You can easily find what you need—when you need it―with Instant Search and live icon previews that display the actual contents of your files. And while you''re at it, give your personal productivity a boost with instant access to the information you care about using Windows Sidebar and Gadgets. Put these easy-to-use and customizable mini-applications on your desktop and reveal the information you''re looking for at a glance. Website: http://www.microsoft.com/windows/products/windowsvista/seeit/default.mspx' 53 EXEC dbo.InsertPlatfrom 'Apple Mac OS X Tiger', 'Some description for Apple Mac OS X Tiger over here …' 54 EXEC dbo.InsertPlatfrom 'Apple Mac OS X Leopard', 'Desktop: The new look of Leopard showcases your favorite desktop image and puts new file Stacks at your fingertips for a stunning, clutter-free workspace. Finder: Browse your files like you browse your music with Cover Flow. Time Machine: See how your system looked on any given day and restore files with a click. Website: http://www.apple.com/macosx/leopard/features/' 55 EXEC dbo.InsertPlatfrom 'Red Hat Linux', 'Some description for Red Hat Linux over here …' 56 57 SET @Log = @Log + 'Rows In Platform: ' + CAST((SELECT COUNT(PlatformID) FROM Platform) AS varchar(10)) + '<br />' 58 /* *** Start Insert PC *** */ 59 SET @Log = @Log + 'Start Insert PC' + '<br />' 60 61 DECLARE @WinXP int, @WinVista int, @OSXTiger int, @OSXLeopard int, @RedHat int 62 SET @WinXP = (SELECT PlatformID FROM Platform WHERE Title = 'Windows XP SP2 Professional Edition') 63 SET @WinVista = (SELECT PlatformID FROM Platform WHERE Title = 'Windows Vista Ultimate') 64 SET @OSXTiger = (SELECT PlatformID FROM Platform WHERE Title = 'Apple Mac OS X Tiger') 65 SET @OSXLeopard = (SELECT PlatformID FROM Platform WHERE Title = 'Apple Mac OS X Leopard') 66 SET @RedHat = (SELECT PlatformID FROM Platform WHERE Title = 'Red Hat Linux') 67 68 EXEC dbo.InsertPC 'Fusion PC One', 'Description here ...', 'Intel Core2 Duo E6600 2.4 GHz 1066MHz', '1GB Dual Channel DDR2 667 SDRAM', '120GB SATA2 NCQ HDD', 'NVIDIA GeForce 8600 256MB GDDR3', '22" 3000:1 Wide Screen LCD', @WinXP 69 EXEC dbo.InsertPC 'Fusion PC Two', 'Description here ...', 'Intel Core2 Duo E6850 3 GHz 1333MHz', '2GB Dual Channel DDR2 800 SDRAM', '240GB SATA2 NCQ HDD', 'NVIDIA GeForce 8800 Ultra 256MB GDDR3 SLI', '24" 3000:1 Wide Screen LCD', @WinVista 70 EXEC dbo.InsertPC 'Fusion PC Three', 'Description here ...', 'AMD Athlon 64 X2 Dual Core 6000+ 3 GHz', '2GB Dual Channel DDR2 667 SDRAM', '240GB SATA2 NCQ HDD', 'ATI Radeon Cross Fire 2900 256MB GDDR3', '24" 3000:1 Wide Screen LCD', @WinVista 71 EXEC dbo.InsertPC 'Fusion X1', 'Description here ...', 'Intel Core2 Extreme Q6850 3 GHz 1333MHz', '6GB Dual Channel DDR2 800 SDRAM', '500GB SATA2 NCQ HDD', 'NVIDIA GeForce 8800 Ultra 256MB GDDR3 SLI', '30" 3000:1 Wide Screen LCD', @OSXLeopard 72 EXEC dbo.InsertPC 'Fusion X2', 'Description here ...', 'AMD Athlon 64 FX 74 3 GHz', '6GB Dual Channel DDR2 800 SDRAM', '500GB SATA2 NCQ HDD', 'NVIDIA GeForce 8900 Ultra SLI 256MB GDDR3', '30" 3000:1 Wide Screen LCD', @WinVista 73 EXEC dbo.InsertPC 'Fusion Tiger 1', 'Description here ...', 'Intel Core2 Duo E6600 2.4 GHz 1066MHz', '2GB Dual Channel DDR2 800 SDRAM', '120GB SATA2 NCQ HDD', 'NVIDIA GeForce 8600 256MB GDDR3 SLI', '22" 3000:1 Wide Screen LCD', @OSXTiger 74 EXEC dbo.InsertPC 'Fusion Linux 1', 'Description here ...', 'AMD Athlon 64 X2 6000+ 3 GHz', '1GB Dual Channel DDR2 800 SDRAM', '120GB SATA2 NCQ HDD', 'NVIDIA GeForce 8600 256MB GDDR3', '22" 3000:1 Wide Screen LCD', @RedHat 75 76 SET @Log = @Log + 'Rows In PC: ' + CAST((SELECT COUNT(PCID) FROM PC) AS varchar(10)) + '<br />' 77 78 /* *** Start Insert Inventory *** */ 79 SET @Log = @Log + 'Start Insert Inventory' + '<br />' 80 81 DECLARE @F1 int, @F2 int, @F3 int, @FX1 int, @FX2 int, @FT1 int, @FR1 int 82 SET @F1 = (SELECT PCID FROM PC WHERE Title = 'Fusion PC One') 83 SET @F2 = (SELECT PCID FROM PC WHERE Title = 'Fusion PC Two') 84 SET @F3 = (SELECT PCID FROM PC WHERE Title = 'Fusion PC Three') 85 SET @FX1 = (SELECT PCID FROM PC WHERE Title = 'Fusion X1') 86 SET @FX2 = (SELECT PCID FROM PC WHERE Title = 'Fusion X2') 87 SET @FT1 = (SELECT PCID FROM PC WHERE Title = 'Fusion Tiger 1') 88 SET @FR1 = (SELECT PCID FROM PC WHERE Title = 'Fusion Linux 1') 89 90 EXEC dbo.InsertInventory 10, @F1, 2.5, 'iCluster Fusion One' 91 EXEC dbo.InsertInventory 10, @F2, 2.5, 'iCluster Fusion Two' 92 EXEC dbo.InsertInventory 10, @F3, 2.5, 'iCluster Fusion Three' 93 EXEC dbo.InsertInventory 6, @FX1, 6, 'iCluster Fusion X1' 94 EXEC dbo.InsertInventory 6, @FX2, 6, 'iCluster Fusion X2' 95 EXEC dbo.InsertInventory 10, @FT1, 3, 'iCluster Fusion Tiger One' 96 EXEC dbo.InsertInventory 30, @FR1, 2, 'iCluster Fusion Linux One' 97 98 SET @Log = @Log + 'Rows In Inventory: ' + CAST((SELECT COUNT(InventoryID) FROM InventoryPC) AS varchar(10)) 99 100 RETURN @Log if i remove the last line then all is well. but i get "An SqlParameter with ParameterName '@Log' is not contained by this SqlParameterCollection."
i have a huge stored procedure abt 500 lines..and i am calling this sp from an asp.net page...thn i got this error - error converting varchar to numeric - and am trying to debug...is there any way we can find out where the error is coming from...like aproxly which line number..etcor do i have to go through each line manually and see where i am doing the conversion....