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 2000 Forums
 Transact-SQL (2000)
 insert into a table variable value and select reco

Author  Topic 

ranjeetsingh_6
Posting Yak Master

125 Posts

Posted - 2006-09-09 : 04:38:20
Hi
I want to insert values in a table like as

declare @name varchar(10)
set @name='Ranjeet'
INSERT INTO TempAddPlace values (select id from Tablename,@name)

means want to insert some select records from a table and also some variable.

Ranjeet Kumar Singh

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-09-09 : 04:53:18
Somthing like this ??

INSERT INTO TempAddPlace values (select id,@name from Tablename)

Chirag
Go to Top of Page

ranjeetsingh_6
Posting Yak Master

125 Posts

Posted - 2006-09-09 : 04:56:48
Hi
variable @name have calculated value not come from a Table

Ranjeet Kumar Singh
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-09-09 : 05:00:55
Post what are you trying to do??

Yeah, if you want insert the calculated value into any column then this is the method to do so...



Chirag
Go to Top of Page

ranjeetsingh_6
Posting Yak Master

125 Posts

Posted - 2006-09-09 : 05:08:33
Hi
declare @place varchar(50)
set @place='London'(This value Comeing from search a table and have a large code of function )

INSERT INTO TempAddPlace values (select id from Tablename,@place)



Ranjeet Kumar Singh
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-09-09 : 05:13:44
oks, so what you want to do with @place variable, you require to insert the value 'London' in some column of TempAddPlace or London is the Table
and you want to do cross join with the < TableName >and then insert the values into TempAddPlace???



Chirag
Go to Top of Page

ranjeetsingh_6
Posting Yak Master

125 Posts

Posted - 2006-09-09 : 05:26:02
This is my function to Find place this will return place

CREATE FUNCTION place(@lat float,@log float)
RETURNS varchar(128)
AS
BEGIN
declare @la11 float,@lon1 float,@var varchar(30),@latv1 varchar(30),@lonv1 varchar(30),@latmap varchar(30),@lonmap varchar(30),@latv11 varchar(30),@lonv11 varchar(30), @dis float
select @la11 = Lat FROM VEHICLETRACK where lat=@lat and lon=@log
select @lon1 = Lon FROM VEHICLETRACK where lat=@lat and lon=@log
select @var=CONVERT(varchar(30),@la11,0)
select @latv1=SUBSTRING(@var,1,9)
select @var=CONVERT(varchar(30),@lon1,0)
select @lonv1=SUBSTRING(@var,1,9)
--select @latv1,@lonv1
declare @count integer
select @count=count(name) from Map_Places_India
declare @i integer,@CID integer
set @i=1
--set @CID=@i
while @i<@count
begin
select @la11 = Lat FROM Map_Places_India where id=@i
select @lon1 = Lon FROM Map_Places_India where id=@i
select @var=CONVERT(varchar(30),@la11,0)
select @latv11=SUBSTRING(@var,1,9)
select @var=CONVERT(varchar(30),@lon1,0)
select @lonv11=SUBSTRING(@var,1,9)
if @i=1
begin
set @dis=dbo.distance(@latv1,@latv11,@lonv1,@lonv11)
--set select @CID= id from Map_Places_India where id=@i
set @CID=@i
end
else
begin
declare @zz float
set @zz=dbo.distance(@latv1,@latv11,@lonv1,@lonv11)
if @zz<@dis
begin
set @dis=@zz
--set select @CID= id from Map_Places_India where id=@i
set @CID=@i
end
end
set @i=@i+1
end
declare @position varchar(50)
--select @i as Counter
--select @CID as CID
select @position= name from Map_Places_India where id=@CID
declare @place varchar(50)
--select @dis as Distance + 'Km From'+ @position
--select @position as Position
declare @place1 varchar(128)
SELECT @place1=CONVERT(varchar(30), @dis) +' ' + 'Km. From'+' ' + CONVERT(varchar(30), @position)

RETURN( @place1)
END



declare @name varchar(10)
set @name=dbo.place(28.89765432,77.2345678)

INSERT INTO TempAddPlace values (select id from Tablename,@name)



Ranjeet Kumar Singh
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-09-09 : 05:31:17
I guess you want somthing like this

Insert Into TempAddPlace
Select Dbo.Place(28.89765432,77.2345678) ???

Or post the table structure of TempAddPlace...

Chirag
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-10 : 13:57:46
I think is a sequel to this topic http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=71621


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-10 : 14:33:54
See alo this topic http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=71720


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -