Home Forums SQL Server 2005 T-SQL (SS2K5) T-SQL Function that works like the FIRST funcion in MS Access? RE: T-SQL Function that works like the FIRST funcion in MS Access?

  • Are you by chance doing this in SSRS? If so, you should turn your sql into a stored procedure instead of putting the sql in your report.

    I don't think so... I am doing this in a view in SQL Server Studio Management Express (SQL Server 2005). Maybe it is because it is the express version?

    No problem. Just trying to emphasize the importance of testing the scripts you post.

    Totally understand, I hontestly was pretty lost with that whole part, but I am getting the hang of this.

    Thank you for the help with combining the names, it worked perfectly.

    --------------------------

    Now there is one last slightly more complicated piece to this puzzle that I have... and then I think I am actually 100% done with this project.

    I think there are two ways to get what I need, the first (A) is preferred. I'll explain what I mean below.

    (A)

    For the space_type column, there are several different values which it can have (Workspace, Office, bathroom, etc.) If there are 0 employees in a space_type: Workspace, the name1 column would read 'Vacant Cubicle' instead of being NULL. If there are 0 employees in a space_type: Office, the name1 column would read 'Vacant Office' instead of being NULL. If there are 0 employees in any other space_type, nothing will happen, name 1 will be NULL.

    (B)

    Pretty much same as in (A) except that a new column entirely could be created (let's call it 'Vacancy'). This column will take on the value 'Vacant Cubicle' if there are 0 employees in the space and it is of the space_type: Workspace. This column will take on the value 'Vacant Office' if there are 0 employees in the space and it is of the space_type: Office.

    I have been messing around with the CASE WHEN and I just can't seem to get the syntax correct and functional. Probably because I have such an unsure footing when it comes to the fundamentals of this language. Hopefully you can help! 🙂 Thank you in advance.