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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 insert into a table variable value and select reco
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ranjeetsingh_6
Posting Yak Master

India
125 Posts

Posted - 09/09/2006 :  04:38:20  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
1907 Posts

Posted - 09/09/2006 :  04:53:18  Show Profile  Visit chiragkhabaria's Homepage  Send chiragkhabaria a Yahoo! Message  Reply with Quote
Somthing like this ??

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

Chirag
Go to Top of Page

ranjeetsingh_6
Posting Yak Master

India
125 Posts

Posted - 09/09/2006 :  04:56:48  Show Profile  Reply with Quote
Hi
variable @name have calculated value not come from a Table

Ranjeet Kumar Singh
Go to Top of Page

chiragkhabaria
Flowing Fount of Yak Knowledge

India
1907 Posts

Posted - 09/09/2006 :  05:00:55  Show Profile  Visit chiragkhabaria's Homepage  Send chiragkhabaria a Yahoo! Message  Reply with Quote
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

India
125 Posts

Posted - 09/09/2006 :  05:08:33  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
1907 Posts

Posted - 09/09/2006 :  05:13:44  Show Profile  Visit chiragkhabaria's Homepage  Send chiragkhabaria a Yahoo! Message  Reply with Quote
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

India
125 Posts

Posted - 09/09/2006 :  05:26:02  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
1907 Posts

Posted - 09/09/2006 :  05:31:17  Show Profile  Visit chiragkhabaria's Homepage  Send chiragkhabaria a Yahoo! Message  Reply with Quote
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

Sweden
30421 Posts

Posted - 09/10/2006 :  13:57:46  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

Sweden
30421 Posts

Posted - 09/10/2006 :  14:33:54  Show Profile  Visit SwePeso's Homepage  Reply with Quote
See alo this topic http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=71720


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000