Solved

sql sproc procedure

Posted on 2015-02-22
4
104 Views
Last Modified: 2015-02-22
Hi there!

The procedure created/altered below works as expected:

----------------------------------
ALTER PROCEDURE [dbo].[net_upd_FullQuestDB_sproc]
(
      @questDBID int,
      @QuestLevel int = null
AS
BEGIN
  If ISNULL(@QuestLevel, 0) != 0
  BEGIN
  UPDATE dbo.QuestionsDB
  SET
  QuestLevel = @QuestLevel
  WHERE QuestDBID = @questDBID
  END
END

GO
----------------------------------

But the one below, which seems "logically" equivalent, does NOT work unless I try only numbers in the field...

ALTER PROCEDURE [dbo].[net_upd_FullQuestDB_sproc]
(
      @questDBID int,
      @OriginalImgQuestion nvarchar(150) = null
AS
BEGIN
  If ISNULL(@OriginalImgQuestion, 0) != 0
  BEGIN
  UPDATE dbo.QuestionsDB
  SET
  OriginalImgQuestion = @OriginalImgQuestion
  WHERE QuestDBID = @questDBID
  END
END

GO


It seems as if the procedure cannot take into account that I defined int in one case and nvarchar(150) in the other case... but it should consider that and make the second sproc work.... am I wrong?  (Of course I am, otherwise this would not be an EE post, right?!)

Please help!  :)

P.S.: when I run this procedure like:

SQLsproc =  "net_upd_FullQuestDB_sproc @questDBID = " & questDBID & ", @OriginalImgQuestion = N'" & OriginalImgQuestion & "'"

and I use OriginalImgQuestion  as say "1234" it works, but when I use the same field value as "abc", it does not work...
0
Comment
Question by:fskilnik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40624555
Be consistent with your types! Both the isnull and the comparison should use strings.
If ISNULL(@OriginalImgQuestion, '') != ''

Open in new window

0
 

Author Comment

by:fskilnik
ID: 40624566
Perfect, Qlemo!

It worked as expected, of course!  :)

Just one related-question, please: and when the type is "datetime", how should be the comparison (as strings)?

Thanks a lot!
fskilnik.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40624586
To do it right is more difficult, as you do have no native date constant representation. But luckily any date can be converted to string. You can use exactly the same syntax as for strings - if you want to check for empty values, that is.
0
 

Author Comment

by:fskilnik
ID: 40624597
Great, Qlemo. Thanks for the info and for the answer to this post, of course!   :)

I have put another EE post VERY related to this a couple of minutes ago... if you have time, I would be very glad if you could help me there!!

There means Here: http://www.experts-exchange.com/Database/MS-SQL-Server/Q_28622155.html

Thanks a lot, really.

Regards,
fskilnik.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Format Data Field - SQL 11 42
Access join syntax when converting to T-SQL query 4 44
Comparison query - 4 columns 9 42
compare date to getdate() 8 17
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question