Viewing 33 posts - 1 through 33 (of 33 total)
  • Any SQL language experts in the house?
  • DezB
    Free Member

    Got a simple question, but I’m sh1t at SQL! Can ye help?

    geoffj
    Full Member

    Fire away – I’m sure there are a few SQL geeks on here (not that good myself mind!).

    dooosuk
    Free Member

    Not without the question we can’t.

    retro83
    Free Member

    depends what the question is!

    DezB
    Free Member

    Just fishing first!

    Well, er. I suppose I’ll have to paste the thing to explain it. I’m making an SMS collection

    I’ve got:
    from SMS_R_System where SystemOUName like “%thcg.net/EU/Gosport Data Center/%Workstations” and (NetbiosName like “%-1%” ..etc

    with me so far?

    DezB
    Free Member

    sorry thats just a section of the query, in case you were wondering!

    Nezbo
    Free Member

    I have one if you want to help

    this is my query

    SELECT Patient.Provider, Count(Patient.[Date entered]) AS [Patients Assigned], DatePart(“y”,DateAdd(“d”,+1,Now())) AS Expr1
    FROM Patient
    WHERE (((Right(Left(Patient.[Date entered],5),2))=DatePart(“m”,(DateAdd(“m”,-5,Now())))))
    GROUP BY Patient.Provider;

    The part in bold is where i want to display just the year?

    Cheers,
    Nezbo

    Nezbo
    Free Member

    I have tried

    DatePart(“Y”, now())

    with no joy…

    DezB
    Free Member

    all I want to do is select from more SystemOUNames.

    so.. where SystemOUName like “%thcg.net/EU/Gosport Data Center/%Workstations” or “%thcg.net/EU/Gosport Data Center/%Laptops” and (NetbiosName… etc.

    Can I do that with wildcard values?
    Apologies if this is really badly explained!! So you get me drift?

    DezB
    Free Member

    Bugger off Nezbo!

    I think I need to do this – where SystemOUName like “%thcg.net/EU/Gosport Data Center/%Workstations” or SystemOUName like “%thcg.net/EU/Gosport Data Center/%Laptops” and (NetbiosName…

    Do I need brackets somewhere?
    This is making me sweat.

    molgrips
    Free Member

    Brackets round the Or clauses if I were you.

    Nezbo
    Free Member

    if you past the whole statement we will ahve a better understanding?

    🙂

    DezB
    Free Member

    where SystemOUName like (“%thcg.net/EU/Gosport Data Center/%Workstations” or SystemOUName like “%thcg.net/EU/Gosport Data Center/%Laptops”) and (NetbiosName…

    just that?

    DezB
    Free Member

    if you past the whole statement we will ahve a better understanding?

    OK. After what mogrips said, will this baby work?

    select SMS_R_System.ResourceID,SMS_R_System.ResourceType,SMS_R_System.Name,SMS_R_System.SMSUniqueIdentifier,SMS_R_System.ResourceDomainORWorkgroup,SMS_R_System.Client from SMS_R_System where (SystemOUName like “%thcg.net/EU/Gosport Data Center/%Workstations” or SystemOUName like “%thcg.net/EU/Gosport Data Center/%Sales laptops” or SystemOUName like “%thcg.net/EU/Gosport Data Center/%Laptops”) and (NetbiosName like “%-1%” or NetbiosName like “%-2%” or NetbiosName like “%-3%”)

    Nezbo
    Free Member

    (SystemOUName like “%thcg.net/EU/Gosport Data Center/%Workstations” or SystemOUName like “%thcg.net/EU/Gosport Data Center/%Laptops”)

    I would start with the brcket movement…

    DezB
    Free Member

    That looks the same as mine? (Which returns nothing)

    EDIT: Hang on, looks like it’s worked!

    Thanks folks!

    GrahamS
    Full Member

    Nezbo,
    DatePart("y", now()) gives you “day of year”.

    For the year use:
    DatePart("yy", now())
    or
    DatePart("yyyy", now())

    Assuming this is DatePart in Microsoft Transact SQL

    andywhit
    Free Member

    Pretty ugly and inefficient query performing wildcard searches on character fields. But if you’re stuck with a poorly designed database schema then what can you do 😀

    DezB
    Free Member

    andywhit – Member
    Pretty ugly and inefficient query performing wildcard searches on character fields. But if you’re stuck with a poorly designed database schema then what can you do

    Ugly as hell, but that’s Microsoft Active Directory for ya. [/geek=off]

    Nezbo
    Free Member

    I am useing MS access 😳 yes i know…

    but my code is now

    SELECT Patient.Provider, Count(Patient.[Date entered]) AS [Patients Assigned]
    FROM Patient
    WHERE Right(Left(Patient.[Date entered],5),2)=DatePart(“m”,(DateAdd(“m”,-5,Now()))) And Right(Patient.[Date entered],2)=FORMAT(Now(),’YY’)
    GROUP BY Patient.Provider;

    It will just not display any results 🙁

    The bolded part is where i am having the problem…

    GrahamS
    Full Member

    What’s with all the Left, Right stuff??

    Is Patient.[Date entered] a text string? If so, why isn’t it a Date??

    Nezbo
    Free Member

    I am not to sure how to convert it to a date, because MS Access does not use CONVERT ?

    Patient.[Date entered] is a text string.

    GrahamS
    Full Member

    Right, there is your first problem. Why is something called “Date entered” being stored as text??

    That rather points to a larger problem with your system design. What if “Date entered” is “25/12/2007”, “12/25/2007”, “2007/12/25”, “Monday”, “last week” etc etc etc

    The application should be dealing with what the user enters. By the time it gets to the database it should be in a sane format.

    Nezbo
    Free Member

    The problem is that I have inherited the database and there is around 30,000 records so I guess the date format in MS Access Database is going to stop at DD/MM/YYYY 🙁

    I know it is not the best database design practised.

    coffeeking
    Free Member

    I had all sorts of problems with a column called “date” – boy did it screw up SQL, it got its knickers in a twist due to it conflicting with a function.

    tommo
    Free Member

    UPDATE EMP
    SET SALARY = ‘1000000’
    WHERE EMP_NAME = ‘tommo’;

    Job Done.

    mudshark
    Free Member

    A column called date?! I’m an Oracle developer and had to develop using SQL Server once; was an upsetting experience for me….

    GrahamS
    Full Member

    You could change the database design pretty easily and migrate the data – it would just depend how much other code expected that column to be text.

    But if you’re stuck with it..

    The easiest way to figure out what’s going on here is to try another query:

    select Right(Patient.[Date entered],2), FORMAT(Now(),'YY')
    from Patient

    ..will show you what you are actually trying to compare. The most obvious thing I can see it that I think it should be 'yy' and not 'YY'

    andywhit
    Free Member

    SELECT * FROM EMP WHERE EMP_NAME = ‘tommo’;

    EMP_NAME SALARY SALARY_CURRENCY_CODE
    tommo 1000000 ZWL

    SELECT * FROM CURRENCY WHERE CURRENCY_CODE = ‘ZWL’;

    CURRENCY_CODE DESCRIPTION
    ZWL ZIMBABWEAN DOLLAR

    Pwned!

    damitamit
    Free Member

    Nezbo, if its an Access query you could prolly use CDate(String) in the statement. Then use date functions on the value. Thou probably best to check if the CDate is creating the right ‘Date’ first.

    Nezbo
    Free Member

    WAhooooooooooooo got it working with the cDate 🙂 Cheers damitamit 🙂

    SELECT Patient.Provider, Count(Patient.[Date entered]) AS [Patients Assigned]
    FROM Patient
    WHERE DatePart(“m”,cDate(Patient.[Date entered]))=DatePart(“m”,(DateAdd(“m”,-1,Now()))) AND DatePart(“yyyy”,cDate(Patient.[Date entered]))=DatePart(“yyyy”,Now())
    GROUP BY Patient.Provider;

    Cheers,
    Nezbo

    GrahamS
    Full Member

    So is now a good time to point out that this query won’t work in January? 🙄

    damitamit
    Free Member

    lol, indeed

Viewing 33 posts - 1 through 33 (of 33 total)

The topic ‘Any SQL language experts in the house?’ is closed to new replies.