0

Hi,

I have a variable @FranchiseId declared in my stored procedure

If I try the following select command, will it work????

SELECT @FranciseId=(select FranchiseName FROM franchise WHERE username=@username),username
FROM MyTable

I hope you Understood My problem!!

2
Contributors
10
Replies
11
Views
6 Years
Discussion Span
Last Post by arsheena.alam
0

@debasisdas Thanks!!
But I need to fetch the value of "@franchiseId" variable from franchise Table and then display this variable's value along with other columns from the Mytable table.Moreover I have to use this value with joins once the value is fetched correctly.

should I Do it dis way:

SELECT FranciseId=(select FranchiseName FROM franchise WHERE username=@username)
INTO Mytable

I think this will insert the frachiseId column value into the Mytable and from their i can fetch the records..
Is it correct????

0

franchise is the table from where i have to fetch franchise id
and Mytable is the table in which i have records based on that franchise id

0

try this

SELECT f.FranchiseName INTO @FranciseName 
FROM franchise f , mytable m 
WHERE f.username=@username
and f.franchiseid = m.franchiseid
0

@debasisdas Thanks :)

This query will work after some editing i.e:

SELECT f.FranchiseName INTO @FranciseName
FROM franchise f
WHERE f.username=@username


Now I need to insert this variable(FranciseName) value in another table which contains a column as franchiseID in the same query.
The table name is F1 and the column name is franchiseID

what will be the correct command to execute the above!!

Thanks in advance!!

0

@debasisdas: oops!! sorry!! I tried but the command did not work...

Is their any other way to store/select/fetch the value of one column from a table into a variable declared by us and then use that variable value in other queries????

Please give solution to this!!!!

0

try this sample SQL

INSERT INTO tbl_temp2 (fld_id)
  SELECT tbl_temp1.fld_order_id
  FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;
0

@debasisdas Thanks for your reply!!
Appreciate your help:)
I got my quesry solved!!
i needed to declare a table type variable and store the value into it!!

0

My Query was solved by the following commands:

Create Table F_ID(franchiseId varchar(20))

insert into F_ID
select Franchises
From franchise


Declare @tempF_ID Table(franchiseId varchar(20))

Declare @ID varchar(100)

set @Id='select * from F_ID'


insert into @tempF_ID
exec(@ID)

select @ID=franchiseId from @tempF_ID

print @ID

now the @ID variable stores the of franchise ID

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.