Results 1 to 7 of 7

Thread: Need SQL Query Help

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Posts
    154
    I need to write a similiar SQL query on a SQL server.

    This query determines if the "Weekday" = Monday. If it does then the DayImport result = MONDAY if it equals something other than 2 it supplies a result of OTHER. This was written in Access97 and works great. I am trying to convert my application to SQL server and can't figure this one out.

    SELECT tMaster.DT_Import, IIf(Weekday([dt_import])=2,"MONDAY","OTHER") AS DayImport
    FROM tMaster;

    Can it be done?

  2. #2
    Lively Member
    Join Date
    Jan 2000
    Posts
    76

    Try this DATENAME(wk, date)

    Instead of Weekday try DateName(wk,date)
    see Transact SQL Help

  3. #3
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    You won't be able to use IIF as part of a sql statement on SQL server. You can, though, create a stored procedure to to the same thing...

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Posts
    154
    Can you give me a really simple example?

    Hey you seem to be using SQL server. Can I ask you anopther question. I am using a Data Control to access the SQL server. However, when I try and click on the control to move it forward, backward, etc, it just freezes on me?

    Thanks

  5. #5
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Try this:

    Code:
    if exists (select * from sysobjects where id = object_id('dbo.cp_getWeekDay') and sysstat & 0xf = 4)
    	drop procedure dbo.cp_getWeekDay
    GO
    CREATE PROCEDURE cp_getWeekDay
    as
    
    
    create table #tempWkDay (
           DT_Import smallint not null,
    	DayImport char(6))
    
    insert into #tempWkDay SELECT DT_Import, "Monday" FROM tMaster where dt_import=2
    insert into #tempWkDay SELECT DT_Import, "Other" FROM tMaster where dt_import not = 2
    
    
    SELECT * from #tempWkDay
    GO
    WRT your other question, I don't use controls against SQL server.

    [Edited by JHausmann on 04-05-2000 at 02:25 PM]

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Posts
    154
    Thanks for this code, I will look at it.

    Why don't you use controls? I have a database that has about 25 fields associated with a customer such as name, addr, city, state, etc. It seems much easier for me to bind these to a data control rather than populate them.

    I am curious how you get around this without a bunch of code. Or maybe you are writing different type of app.

    Thanks

  7. #7
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    The main database I support has over 100 tables, some with hundreds of fields. The data gets moved from client apps to the servers (multiple locations) which then replicates to a central server. The central server passes data through to a single MVS DB2 database, which feeds a unix based system. The data transfer from the client to the servers is handled via a C++ based .dll. It compares the client database to the server database and, if the structures are compatible, it sends the data.

    I have a handful of VB applications that access some of the data but none use a data control because I find them too restrictive. I may have to code more but my code does what I want when I want.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width