SQL HELP

  • Hi,

    i need help on this.i have a query as below

    select *

    from [Header$]

    WHERE [Project #] is not null

     

    I WANT TO RAISE ERROR WHEN [Project #] is not null

     

    Any help is appreciated

  • IF (SELECT COUNT(*) FROM [Header$] WHERE [Project#] IS NOT NULL) > 0

    THEN

    RAISERROR(.......)

  • i need to know what is the syntax for RAISE ERROR

  • The syntax is in BOL under the keyword RAISERROR. Note that it's one word, and that it's technically missing an "e", but that's where it's located.

  • i have found it but i cant still make it work.i would appreciate if you can help me in this case

  • Show us the code you have so far, and we can figure out what's wrong with it.

  • IF

    (SELECT COUNT(*) FROM [Header$] WHERE [Project#] IS NOT NULL) > 0

    THEN

    RAISERROR

    ('Hi there, I ' ' an error',1,1)

    end

  • SQL Server doesn't use IF/THEN syntax, it's just an IF (using begin/end for blocks of statements). Your "end" needs a matching "begin" as well. What is the space surrounded by single quotes in the middle of your error string supposed to do? It just breaks up the string into two pieces, thus causing a syntax error.

  • SELECT

    *

    FROM

    [Header$]

    WHERE

    [Project #] IS NOT NULL

    IF

    @@ERROR = 0

    RAISERROR

    ('Please enter.',1,1)

     

    IS THAT FINE YOU THINK OR IT STILL HAS PROBLEM

  • Now I'm totally lost. Why did you add the @@ERROR, and why does your message now say "Please enter", and why do I feel like this is homework?

    Based on my reading of your original question, using your code prior to this latest post and fixing the issues I noted, will do what you want. I don't know what you're trying to accomplish with this latest bit of code.

  • Best,

    did you read answers here:

    http://qa.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=355132 ?

    Did you get it?

    Can you repeat what did you get?

    _____________
    Code for TallyGenerator

  • LET ME TELL YOU THE EXACT SITUATION

    iam using SSIS.I have created a package which gets data from excel and import into sql server database.

    now what is happening is i use the following sql command to get the data at the source level from excel

    select *

    from [Header$]

    now iam trying to USE RAISERROR in case the column [Project #] is not null in the sql command.The column [Project #] is one of the column in my excel sheet [Table-Header$]

     

  • Why do you want to raise an error if there is a value in the column? If you don't want that value, just don't bring it across. What are the exact conditions that would need to be met for your transfer to be considered successful?

     

  • Once again.

    Did you read it?

    Did you get it?

    _____________
    Code for TallyGenerator

Viewing 14 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply