Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Error

Author  Topic 

yaman
Posting Yak Master

213 Posts

Posted - 2008-05-02 : 04:20:28
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER proc [dbo].[stp_Level1Add]
@Level1Name varchar(100),
@LanguageID int,
@OrgID int,
@Level1ID int OUTPUT
as

Declare @LanguagePostfix varchar(5),@str VARCHAR(400)
SET @STR='INSERT INTO tbl_Level1'
set @LanguagePostfix = (select Postfix from tbl_Language where langID = @LanguageID)

Declare @columnName varchar(20)
set @columnName = 'Level1Name_' + @LanguagePostfix
print @columnName
--print @columnname
if not exists(select * from tbl_Level1 where @columnName=@Level1Name and orgID=@OrgID)
begin
SET @STR='INSERT INTO tbl_Level1' + '(' + @columnName + ',orgID' + ')' + 'Values' + '(' +@Level1Name+ ',' + @orgID + ')'
EXEC @STR

SELECT @Level1ID=SCOPE_IDENTITY()

end
-------------------------------------------------
EXEC
--------------------
EXEC @return_value = [dbo].[stp_Level1Add]
@Level1Name = N'General Administrative Department',
@LanguageID = 1,
@OrgID = 1,
@Level1ID = @Level1ID OUTPUT
---------------------------------------------------
ERROR
-----------------------
Conversion failed when converting the nvarchar value 'INSERT INTO tbl_Level1(Level1Name_HIN,orgID)Values(General Administrative Department,' to data type int.

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

Yaman

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2008-05-02 : 04:30:27
This would probably do the trick:
SET @STR='INSERT INTO tbl_Level1 (' + @columnName + ', orgID) Values (''' +@Level1Name+ ''',' + @orgID + ')'
EXEC @STR


--
Lumbago
Go to Top of Page

yaman
Posting Yak Master

213 Posts

Posted - 2008-05-02 : 04:37:36
Sir
Still Error

Conversion failed when converting the nvarchar value 'INSERT INTO tbl_Level1 (Level1Name_ENG, orgID) Values ('General Administrative Department',' to data type int.

Yaman
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2008-05-02 : 04:47:48
What does PRINT @STR give you?

--
Lumbago
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-02 : 04:59:59
Dup post:-
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=102121
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2008-05-02 : 05:10:35
Aaaargh! Hate that

--
Lumbago
Go to Top of Page

yaman
Posting Yak Master

213 Posts

Posted - 2008-05-02 : 05:34:49
Sir
Its Not Print The Statement
Its Gives A error

Conversion failed when converting the nvarchar value 'INSERT INTO tbl_Level1 (Level1Name_ENG, orgID) Values ('General Administrative Department',' to data type int.

Yaman
Go to Top of Page
   

- Advertisement -