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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to insert

Author  Topic 

companionz
Yak Posting Veteran

54 Posts

Posted - 2009-07-08 : 04:41:01
i want to insert run time values into table how to do this?

something like this:

Declare @temp varchar(10)
Declare @temp1 varchar(20)
Declare @temp3 varchar(20)

set @temp = 'asd'
set @temp1 = 'asdfsdf'
set @temp3 = 'testubg'

insert into tempprint
select @temp, ''@temp1'+ @temp1 '', '@temp3 + '@temp3''

Thanks,
Sourav

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-08 : 04:49:11
table tempprint has how many columns ?

What are the data type of these columns ?

How do you want to insert into the table ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-08 : 04:56:57
What do you expect from this?

select @temp, ''@temp1'+ @temp1 '', '@temp3 + '@temp3''

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

companionz
Yak Posting Veteran

54 Posts

Posted - 2009-07-08 : 05:04:48
Table tempprint definition:
Columns datatype
-------- ---------
Procname varchar
printdata varchar
period datetime


its just that i want to insert values of multiple variables with the name of the variable in printdata column.

Thanks,
Sourav
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-08 : 05:12:12
maybe something like this

insert into tempprint (Procname, printdata, period)
select @temp, '@temp1 ' + @temp1 + ' ' + '@temp3 ' + @temp3, getdate()



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

companionz
Yak Posting Veteran

54 Posts

Posted - 2009-07-08 : 05:20:06
@khtan

It works but the issue is that i've around 20 variables that are to be inserted in printdata field.. Now the datatype for those variables are varchar, tinyint, datetime etc.. i mean mix of datatypes.. How to go about that?

Thanks,
Sourav
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-08 : 05:25:18
if it is not a string data type you have to convert to string before concatenate

declare @temp4 int

insert into tempprint (Procname, printdata, period)
select @temp, '@temp1 ' + @temp1 + ' ' + '@temp3 ' + @temp3 + ' ' + @temp4 ' + convert(varchar(10), @temp4), getdate()




KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

companionz
Yak Posting Veteran

54 Posts

Posted - 2009-07-08 : 10:00:08
It helped.. Thanks
Go to Top of Page
   

- Advertisement -