In a table, I store an integer to represent a day of the week (1 = sunday ) and then in procedures, compare that to datepart(dw, getdate()) to do alternative tasks on certain days.
If I have the number 1, is there a built in function to convert that to sunday or should one just write a function to do just that?
How do we convert both of them into a single SQL DateTime field such as "2015-07-16 01:23:45.000" so that it can be used in a join restricting to a date time in a different SQL File that properly has the DateTime in it?
This works well for converting the transDate Part in the select statement:
  dbo.IntegerToDate(at.transDate) as transDate
  * That returns: "2015-07-16 00:00:00.000"
* The resulting data must work directly in a Microsoft SQL Server Management Studio Query using either using the "on" statement or part of the "where" clause. In other words, NOT as a stored procedure!
Also must be able to be used as a date difference calculation when comparing the 2 files Within say + or - 5 seconds.
I have a query that run every day to update a summary table which has week number and day of week. what I currently do is delete all records from the summary table and then summarize all the data availabe from four tables adn then populate the table daily. I want to know if I can run the update query to run only for the week number and day of week depending on getdate. Can I do this?
select DATENAME(WEEKDAY,[date]) as DAY, sum(earnings) as Earnings from myTable where DATENAME(WEEKDAY,[date] in ('monday','tuesday','wednesday','thursday','friday') group by DATENAME(WEEKDAY,[date]) order by DAY
this query works very well except the last line. the last line causes SQL-Server to order the days in an alphabetical order.What do I have to do that SQL-Server orders the days according to their natural appearance (monday, tuesday, wednesday, thurs......)
Hey, Im pretty sure this is possible, but let me know if it isnt.I have a table of dates in the format "DD/MM/YYYY", is there a way of converting it to output the day of the week? for example 16/11/2007 would display Friday insted.Thanks in advance John
Hi All I'm getting an error that says that this can't be converted to an integer. Here is the line that gets the error. dt = ((DataView)(EventDataSource1.Select(dssa))).ToTable() I have also tried. dt = (DataView)(EventDataSource1.Select(dssa); I am programming in VB here is teh rest of my code. Dim EventDataSource1 As New SqlDataSource()EventDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ToStringDim dssa As New DataSourceSelectArguments()Dim EventID As String = ""Dim DataView = ""Dim dt As New Data.DataTableDim conn As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ToString())Dim cmd As New Data.SqlClient.SqlCommand("SELECT EventID FROM Event WHERE ([StartDate] = @StartDate)", conn)EventDataSource1.SelectCommand = ("SELECT EventID FROM Event WHERE ([StartDate] = @StartDate)")conn.Open()dt = ((DataView)(EventDataSource1.Select(dssa))).ToTable()EventID = dt.Rows(0)(0).ToString()EventDataSource1.SelectParameters.Add("@StartDate",StartDate)EventID = cmd.ExecuteScalar()
I have the following stored procedure for creating a transaction record and after inserting the record, the transaction id is returned.-----------------------------------------------------DECLARE @TransactionID int <------ INSERT statement (after inserting the record, select the identity ID) ---------> Select @TransactionID = @@Identity RETURN------------------------------------------------------...Dim transactionID As Integerconnection.Open()Dim reader As SqlDataReaderreader = command.ExecuteReader(CommandBehavior.CloseConnection)Dim p3 As New SqlParameter("@TransactionID", SqlDbType.Int)p3.Direction = ParameterDirection.OutputtransactionID = Convert.ToInt16(p3.Value)connection.Close()...I wanna retrieve the transactionID of the newly inserted record so that I can use it in my next step of inserting a new record to another table which has reference to the transactionID as a foreign key. However, I encountered error and suspect that it is due to the conversion of the output to Integer as it worked when I tested using dummy Integers.I tried many different ways of conversion but couldn't resolve the error. Could anyone help?
Hi folks, I'm trying to import data from a text file (UnicodeData.txt) into an SQL table. Some of the fields are unicode values (16 bits) expressed as four hexidecimal digits. I've succeeded in importing the data as character strings, but I have not found a way to convert them into numbers. (They could be stored as int or nchar.) I've tried convert(binary/int/whatever, string); E.g. select convert(int, '0x1111') from import_unicode gives the error Syntax error converting the varchar value '0x1111' to a column of data type int.
I could write code to strip off one character at a time, convert the hex digit to a decimal value, shift left, etc., but I find it hard to believe that's the best way.
Any help is appreciated. Please email answer to lars_huttar@sil.org as I don't read this board.
hi i want to insert the varchar value inter column, how can i convert the values and insert in to the record if i give direct column name i am getting a message insert into EMP(id) SELECT name from STU
i am getting a message like this Syntax error converting the varchar value '200.00' to a column of data type int.
I have checked the forums but couldnt find exact term. I have written tsql statement but I dont know how to use that in SSIS this is a update statement in oledb command component... I wanna get integer like YYYYMMDD ( 20080325)
I want to convert date to week consider saturday is first day of week and friday is end of week. for input is orderdate and output should be week. example orderdate 11.04.15 to 17.04.15 week should be 16. orderdate 18.04.15 week should change to 17.
Order DateWeek 11-Apr-201516 12-Apr-201516 13-Apr-201516 14-Apr-201516 15-Apr-201516 16-Apr-201516 17-Apr-201516
Hi, I am extracting data from DB2 into SQL server using DTS. We have the data type char(5) in DB2 and int in SQL server. I tried to give the select integer(columname) as columname from tablename in data source. I did parse the query it was Ok but If I tried to execute that giving the following error. Can you give me your answere for this issue.
--------------------------- Package Error --------------------------- Error Source : Microsoft OLE DB Provider for ODBC Drivers
Error Description : [StarQuest][StarSQL ODBC Driver][DB2]THE VALUE OF A CHARACTER STRING ARGUMENT WAS NOT ACCEPTABLE TO THE INTEGER FUNCTION
--------------------------- OK ---------------------------
declare @found int; set @found = 'select sid from StickyContent where StickyId='+0+' and UserId='+171 exec (@found) delete from StickyContent where sid = @found
I need to pass this statement from my UI i.e in a single query. I am getting this error.
"Conversion failed when converting the varchar value 'select sid from StickyContent where StickyId=' to data type int. "
I want to convert a string into an interger so that my parameter can get one value, and have a seperate matrix list the value before the value selected.
My parameter is year. The user picks the year. And i want the crashcounts for the year displayed in the matrix. Then i have another matrix with a dataset similiar. I want this seperate Matrix/Dataset to display the previous year.
SO if the user selects 2004 from the dropdown. 2004 is displayed in the first matrix, and 2003 is displayed in the second matrix. The year attribute is in string format, and i cant change it in the cube. So i was told it could be converted in reporting services. with this
I have imported a text file with various data into sql table. all these values have been imported as nvarchar. I need to convert these into Integer. the format of the values is 10length i.e. 0000000.00. example of data: 0001028.99 - needs to be shown as 1028.99 222.00 - needs to be shown as 222.00 0000190.89 - needs to be shown as 190.89 2708.99 - needs to be shown as 2708.99 00000-50.99 - needs to be shown as -50.99 -109.79 - needs to be shown as -109.70
as you can see some of the values have leading zeros and some don't. i have tried converting from nvarchar to int and i get the error cannot convert nvarchar to int, i believe it may be because the data contains negative values as well as positive values.
Is there a split function or position function which i can use to extract the data? or any other methods which i can use would be really helpful.
I don't know if this can be done, but hopefully one of the experts in this forum cna help me out.
I have a TimeOff table which contains 5 fields: timeoffID, employeename, startdate, enddate, and timofftype. I need to create a report which shows how many people take sick day (one of the timeofftypes) on each week day (i.e. Monday, Tuesday, Wednesday, and etc.) The problem is that I don't know how to convert the date range (from startdate to enddate) into indvidual week day for each timeoff record.
For example, on the table,
TimeoffID employeename startdate enddate timeofftype 1 Andy 11/02/2006 11/03/2006 Sick Day 2 Bill 11/03/2006 11/03/2006 Sick Day
In VBA, CLng(Now) will return the integer portion of a date CLng(Now) returns 41928, CDate(41928) then returns 10/16/2014. Is there something equivalent in SQL Server that will allow me to convert an integer value to a date?
In short, how can I convert a 100 year date to Gregorian (any format)?
I am querying DB2 from SSRS. I get an interger back that represents a time like this: HHMMSS (The data type in DB2 is an integer.) I would like to make this representation of the time display a little more friendly. Does anyone have a good idea on how I can change the query or SSRS format to display semi-colons to break up the hours, minutes and seconds? Also, the other issue is that since I don't get leading zeros back....they probably need to be added to this value if the value is not a full 6 characters.
I have a table of zip codes, some with Canadian zips. I'd like to takea zip code and search for nearby zips. For example:Dim theZip As Integer = textbox1.text....Parameter.Add(@ziplow, SqlDbType.Int, 5).Value = (theZip - 10)....Parameter.Add(@ziphigh, SqlDbType.Int, 5).Value = (theZip + 10)SELECT * from ZIPCODES where Cast(zip_code as Integer) BETWEEN @lowzipAND @highzipProblem is the letters in the Canadian records cannot be cast asintegers for this process. I get this error:Syntax error converting the varchar value '53151 1' to a column of datatype int.Is there a SQL query that can exclude if no cast can be made to anInteger?Thanks!Anton
I need to convert a a string column to integer. Before converting, I need to check if it has blank values then convert it to NULL. Someone told me that its easier to convert it to NULL before converting to integer.
I have to use the above comma separated values into a SQL Search query whose datatype is integer. How would i do this Search query in the IN Operator of SQL Server. My query is :
declare @id varchar(50) set @id= '3,4,6,7' set @id=(select replace(@id,'''',''))-- in below select query Id is of Integer datatype select *from ehsservice where id in(@id)
But this query throws following error message:
Conversion failed when converting the varchar value '3,4,6,7' to data type int.
We are trying to compare our current calendar week (based on Monday being the first day of the week) with the previous calendar week.Â
I'm trying to produce a line chart with 2 axis:
- x axis; the day of the week (Mon, Tues, Wed etc - it is fine for this to be a # rather than text e.g. 1 = Mon, 2 = Tues etc) - y axis; the cumulative number of ordersÂ
The chart needs two series:
Previous Week. The running count of orders placed that week. Current Week. The running count of orders placed this week.Â
Obviously in such a chart the 'Current Week' series is going not going to have values along the whole axis until the end of the week. This is expected and the aim of the chart is to see the current week compares against the previous week for the same day.Â
I have two tables:
Orders TableCalendar Table
The calendar table's main date column is [calDate] and there are columns for the usual [calWeekNum], [calMonth] etc.Â
My measure for counting orders is simply; # Orders: = countrows[orders].
How do I take this measure and then work out my two series. I have tried numerous things such as adapting TOTALMTD(), following articles such as these:
-Â [URL] ... -Â [URL] ...
But I have had no luck. The standard cumulative formulas do work e.g. if I wanted a MTD or YTD table I would be ok, it's just adjusting to a WTD that is causing me big issues.