Integer to date in SQL Server 2005

I need to create a loop to pull records that are within a quarter from 2006 to the present.  I have created a routine to increment the months and years using integers to get the begin and end dates for each quarter.  I can't seem to use the integers
to create a date.
DECLARE @EarnYear int,
@Beginer int,
@First int,
@QtrBegin datetime
SET @EarnYear = 2006
SET @Beginer = 1
SET @First 1
SELECT (CAST(CAST(@EarnYear as char(4)) +
right('00' + cast(@Beginer as varchar(2)),2) +
right('00' + cast(@First as varchar(2)),2) as datetime) as @QtrBegin
Can anyone help?  Thanks.

You don't want to do it as integers.  When you put an integer into a datetime you get the date that is that many days since Jan 1, 1900.  Sso if you convert the integer 20060101 to a datetime, you are trying to get the date that is 20,060,101 days
pass 1/1/1900 which would be a date in the year 54921.  But the largest possible datetime value is Dec 31, 9999, so you get an error.
You can do it the way you are doing it - that is build a character value containing '20060101' and converting it to a date.  But the best way to do this sort of problem (and many others dealing with dates) is to build a calendar table.  For information
on how to build a calendar table and some of the many uses for a calendar table, see
http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-calendar-table.html.  (Note that this webpage was written for an older version of SQL Server.  If you are on SQL 2008 or later, you probably want to make the datatype
of the dt column date instead of smalldatetime.)
Once you have this table getting the beginning and ending date of every quarter from 2006 to the present is just
Select Y As [Year], Q As Quarter, Min(dt) As QuarterStart, Max(dt) As QuarterEnd
From dbo.Calendar
Where Y >= 2006 And dt <= GetDate()
Group By Y, Q
Order By Y, Q;
Tom

Similar Messages

  • Can't see data in data tab - sql server 2005

    hello,
    i am connected to a sql server 2005 database (with jtds driver), the connection is ok, i see the tables but i can't see data in data tab.
    i have an error : incorrect syntax
    somebody can help me ?
    thank's in advance
    alex

    definitely. I was going to say, make sure you have the privileges to read data.
    From Microsoft SQL Server 2000 on, it is recommended that you are a member of the db_datareader - so that data in the database can be read
    Barry

  • Importing data from SQL Server 2005 database

    Dear Friends
    Scenario:
    We have built an application for which the database is SQL Server 2005.
    Now, we have planned to switch over to Oracle 8i database.
    There is a field with data type as Varchar(Max) – which can hold data with a maximum length of 231 characters (SQL Server 2005)
    In Oracle 8i, the Varchar2 max size 4000 bytes or characters.
    We want to import the data from SQL Sever 2005 database into Oracle 8i database.In the process, the value for the particular field whose data type set as Varchar(Max) in SQL Server 2005 and contains more than 4000 characters gets automatically truncated while importing into oracle.
    We want the entire characters stored in the field to be imported into oracle database.
    Please suggest solutions.
    Thanks and regards
    Bharath Kumar V

    Use CLOB if the data is purely text data. BLOB otherwise.
    But the question is why you want to switch over to an Oracle version which is de-supported by Oracle?

  • Import data from Sql Server 2005

    We have a requirement where we need to import/access data from an Sql Server 2005 database into an Oracle 9i/10g database? Basically, the need is to create some link between Sql Server and Oracle database? In, case of two Oracle databases we could have used 'dblink' but how can we do the same in this case?
    Regards,
    Rup

    By using a feature called 'Heterogeneous Services' which interfaces with ODBC or oledb.
    Heterogeneous Services is documented in the 'Net administrators manual'.
    Sybrand Bakker
    Senior Oracle DBA

  • Export SharePoint List data to SQL Server 2005 Database

    Hello Everybody,
    I am presently working on a project which handles much larger amount of data. The architecture of the application demands extracting records from the SharePoint (WSS 3.0) and insert into a SQL Server 2005 database. I need to run this job as daily basis. I am thinking of using SSIS (SQL Server Integration Service) for this purpose. But I am new to this technology and I'd like to know how effective this idea to do the job.
    I'd also like to know more about SharePoint's ability to handle huge amount of data when it comes to Reporting.
    thank you,
    Arun

    For Reporting Services, There are web parts available which can be used to render a reporting service report in sharepoint. I have also used a reporting service report directly using Page Viewer Web Part so displaying a reporting services report in sharepoint is very simple task. Important part is to transfer data from Sharepoint list to SQL 2005. so if you want to use SSIS package and there is only one or two list then approach is to write a simple query based on your list id and extract information from sharepoint content database from UserData table, since it is a read only operation so it can work this way. Another way to do it is to write a Sharepoint Timer JOB which runs on a defined schedule and will read your list values and will transfer to your SQL 2005, Another way could be to write your custom web service and write code to transfer from list to SQL 2005. Custom code you will write inside timer or web service will be same code so it is just a different shell you can say. in case of web service, use it in some other application as a regular web service.  
    Let me know if you need further help, You did not mention how many list you have?
    Regards,
    BizWorld.

  • How to select data from Sql server 2005 database tableinto oracle database table

    Hi,
    I have table text1 in sql server database and text2 in oracle database (11g). Now how to move data from SQL Server table into oracle table. So please help me how to do it.
    Thanks a lot in advance.
    rk
    OS: Windows 7 professional

    Hi,
    you can use export/import wizard and specify sql server as a source and oracle as destination.
    I hope this is helpful.
    Please Mark it as Answered if it answered your question
    OR mark it as Helpful if it help you to solve your problem
    Elmozamil Elamir Hamid
    MCSE Data Platform
    MCITP: SQL Server 2008 Administration/Development
    MCSA SQL Server 2012
    MCTS: SQL Server Administration/Development
    MyBlog

  • How to present SAP R/3 data in SQL Server 2005 Reporting service?

    Our company is using SharePoint Portal Server 2003 as our intranet. We are also using SAP R/3 4.6C to run their business. There are huge amount of important data in SAP database. There ere are business needs to present SAP data on SharePoint pages which are easier and more friendly to be accessed by users.
    The top concern for IT people to meet this challenge is DO NOT CHANGE/UPGRADE THE EXISTING SAP SYSTEM which is so far run smoothly and stably. We cannot accept any risk to make big changes on SAP. and now we want to adopt the Microsoft SQLServer 2005 BI Solution. the most challenge is the ETL part.how to extract the data from SAP R/3 Data base to the SQL Server Data warehouse?
    any suggestion or comments is welcome!

    Hi
    1.if you use web templates you can post the URL in share
      point very easily.
      any web developer will do that for you in 2 min.
    2.this is a more chalanging issue.
      the main issue is exacly as you defined it - the ETL.
      the main advantage of BW over most BI tools is its
      connectivity to SAP R3 and CRM.
      But still there are many way's to extract data out 
      of any SAP sys and in R3 the data model makes it quite
      easy.
      In CRM its much more complicated because of the much
      more complex Data Model.
      Here are a few way's to extract data from SAP:
    - olap bapi
    http://help.sap.com/saphelp_bw33/helpdata/en/64/9b8f3c855f0454e10000000a11405a/frameset.htm
    - odbo - vb/.net/c sharp
    'connecting to sap bw using vb and ado md'
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/ee19e9c7-0301-0010-8f84-97e3f6d7b5a6
    'connecting to sap bw with excel and odbo'
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/a06a51f3-0201-0010-8591-b742cfafd267
    'odbo'
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/7f88b390-0201-0010-ae94-fdfd42b13407
    'sap .net connector' (seems old version)
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/fb4dc990-0201-0010-429a-bf43852a6895
    .net connector
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5a04426d-0601-0010-5e99-aeea1cd4aa81
    'Access SAP BW ODS BAPI Using C-Sharp and SAP .NET Connector 2.0' doc can be download here
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/12f6d390-0201-0010-e18d-cdb4554a9e75
    Reg's
    Edan

  • Auto update of date field - SQL Server 2005

    HI folks,
    Is there a way I can automatially tell when a record was last updated?
    I can set a field to get the date by using getdate(), but is there a way SQL server will insert the timestamp, without me having to create the date object in CF, then inserting it.
    I'd like to add a 'last updated' function to my CMS.
    Thanks in advance

    For UPDATE you are looking at trigger.
    http://msdn.microsoft.com/en-us/library/ms189799.aspx

  • Automating Data Migration from SQL Server 2005

    Hi All,
    I need to migrate data from SQL Server 2005 to Oracle DB ( Datawarehouse). The data migration involves updating Dimensions and Fact table. I have got painful job of switching topology to point to over 100 different weekly SQL DBs ( in sequence) and pull the data into DW. How can I automate my ODI process to switch from one after the other.
    Any Ideas?
    KS

    ODI Variables are there to help you with this. Please go through this post at [http://blogs.oracle.com/dataintegration/2009/05/using_odi_variables_in_topolog.html] .
    This will show you how to use a variable Oracle data server.
    On similar lines you should be able to switch to any of your 100 weekly SQL server DBs.
    And loop in a sequence to load data from all of them.
    Hope that helps

  • Crystal Report 8.5 with SQL SERVER 2005 problems

    Post Author: AREVA
    CA Forum: Data Connectivity and SQL
    Hi All !We have some problems with Crystal Reports version 8.5 with SQL Server 2005: 1) When we want to generate a report (using data in SQL Server 2005) we have a popup message error : "impossible to loaded pdssql.dll".2) If we want to use SQL Server 2005, which Crystal Reports version we must used ? Is there any restrictions with this connectivity with 8.5 version ?Please, let me known, all informations about SQL Server 2005 and Crystal Report 8.5.Thanks for all !Best regards Anthony

    Hello Kamlesh,
    There is no expectation that the ActiveX viewer (RDC?) from CR8.5 will work in any version of Visual Studio .NET. There is also no expectation that the ActiveX viewer from CR8.5 will work on a machine with a 64 bit operating system.
    You're using VS2008. You should migrate to the bundled edition of CR for VS2008 (v10.5), the ReportDocument object, and the .NET Windows form viewer or Web form viewer.
    Sincerely,
    Dan Kelleher

  • Sql server replication from SQL SERVER VERSION(7.0) to SQL SERVER 2005

    Hi All,
    We are trying to create a replication between Sql server 7.0 data to SQL server 2005 data . We tried to create a local subscription in Sql server ,when tried to connect to publisher  running in Sql server 7.0 it is showing an error message
    like "This Sql server vresion(7.0) is not supported" .
    Could any one please help us with this issue ?
    Thanks
    Sandy

    Hi CRM_Learner,
    SQL Server version 7.0 Service Pack 4 (SP4) is the earliest version that can participate in a replication topology with SQL Server 2005. We need to verify the version of SQL Server. If you configure transactional replication with updating subscribers,
    for a SQL Server 7.0 Publisher, only SQL Server 7.0 Subscribers are supported. SQL Server 7.0, 2000 was out of support in the SQL Server Forums. I suggest you install SQL Server 2005 or later version to configure the SQL Server replication.
    For more information, there is a detail about using multiple Versions of SQL Server in a replication topology.
    http://technet.microsoft.com/en-us/library/ms143241(v=sql.90).aspx
    Regards,
    Sofiya Li
    If you have any feedback on our support, please click here.
    Sofiya Li
    TechNet Community Support

  • CONNECT SQL SERVER 2005 WITH Oracle 10.2.0.3

    Hi,
    I used URL http://www.databasejournal.com/features/oracle/article.php/10893_3442661_2 but its not working.
    I was reading note# 561033.1 adn planning to try.
    If any one done ,please let me know.

    user587327 wrote:
    its not working" is pretty vague. How about if you tell us
    1) What version of Oracle rdbms you are working with (ok, I see 10.2.0.3 in subject .. good)
    2) what OS it is running on (obviously SQL Server is on Windoze, but that doesn't mean that's where Oracle is) : Linux RHEL 4.4 64 bit
    3) what you are trying to do (get an Oracle database to retrieve data from SQL Server? vice versa? something else?):
    Connect to Oracle database and retrieve data from SQL SERVER 2005.So, you want the Oracle DB to act as a client to the SQL Server db?
    >
    4) what error code (ora-nnnnn or tns-00000) you are getting
    Showing
    SQL> desc spt_values@MYSQL
    ERROR:
    ORA-28545: error diagnosed by Net8 when connecting to an agent
    Unable to retrieve text of NETWORK/NCR message 65535
    ORA-02063: preceding 2 lines from MYSQL
    ----I've never used HSO to SQL Server, so I'm getting out of my area here. However ...
    I'm puzzled by the error msg referencing "Net8". Looks like an Oracle 8i construct but you said your db is 10.2. And since the box is Linux I wouldn't expect to find an old 8i installation lurking on it.
    I searched MetaLink (should be everyone's first resource when trying to understand an error message) for "ora-28545" and got 13 hits.
    >
    5) any other diagnostic messages you might have

  • How to attached a sql server 2008 database on sql server 2005

    Hi,
    I have a backup of database designed over sql server 2008. I need to attacched this on a machine where sql server 2005 is installed and I am getting the message while attaching the database.
    "The database can not be opened because it is version 661.
    the server supports version 611 and earlier"

    You need to install/have another instance of SQL Server 2008, restore over there the database and perhaps create a SSIS package to move objects and data into SQL Server 2005
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Using Oracle Forms Importing Data From SQL Server into Oracle Tables.

    Dear All,
    We are using Oracle Forms 10g in windows XP and having OAS 10g and Oracle database 9i.
    How can we import data from SQL Server 2005 into Oracle tables using Oracle Forms?
    Thanks & Regards
    Eidy

    I have no idea what "Oracle Hetrogenius Services" is, so I can't help you with that, sorry.
    SQL Developer might also assist you. SQL Developer can connect to SQL Server as well as Oracle and has some tools for migration. See the documentation for details:
    http://download.oracle.com/docs/cd/E12151_01/doc.150/e12156/toc.htm
    For additional help on using SQL Developer for this task, please consult Support or the SQL Developer forum: SQL Developer
    Hope this helps,
    Jacob

  • Reading BLOB from SQL Server 2005 using DB Link from Oracle 10g

    Hi All,
    I am trying to read a table's data from SQL Server 2005 using ODBC DB Link created in Oracle 10g (10.2.0.3/4) database. I am not using oracle gateway.
    I am able read all data except for the BLOB data from SQL server 2005. It gives error given below when I try to execute query SELECT * from T_TRANSACTION_DATA@sdeslink inside a stored procedure:
    ORA-22992: cannot use LOB locators selected from remote tables
    Kindly help how to read BLOB from SQL server 2005 inside Oracle 10g.
    Best Regards!
    Irfan

    Irfan,
    If you can read the blob data using 10.2 HSODBC then there should be no problem using the 11g gateway.
    I recommend you download the latest version which is 11.2.0.3 available from My oracle Support as -
    Patch 10404530: 11.2.0.3.0 PATCH SET FOR ORACLE DATABASE SERVER
    This is a full version and does not need a previous version to have bene installed. When installing it needs to be in a completlely separate ORACLE_HOME from the existing 11.2 install.
    For the Ora-22992 problem have a look at this note in My Oracle Support -
    Ora-22992 has a workaround in 10gR2 (Doc ID 436707.1)
    Regards,
    Mike

Maybe you are looking for