SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 need help with query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Pasi
Posting Yak Master

152 Posts

Posted - 07/17/2014 :  14:38:46  Show Profile  Reply with Quote
HI,

I want to run below query as query not SP. when I do it is says the command is successful and I try to run the same query from excel to see what kind of data it pulls but unable , it looks like the excel treat this as SP not as SQL query? what am I doing wrong?
How do I see the results in the SQL management studio when I execute this?
Thanks.

begin
declare
@user_id int
select @user_id=be.created_by
from user_mstr um
inner join ngweb_bulk_enrollments be on be.practice_id=um.practice_id
INNER JOIN patient_encounter pe on pe.person_id = be.person_id
inner join person p on p.person_id=be.person_id
where exists( select user_id
from user_mstr
where @user_id=user_id and
user_id<>'0')
and status ='1'
ORDER BY be.created_by, be.create_timestamp desc
end

tkizer
Almighty SQL Goddess

USA
37123 Posts

Posted - 07/17/2014 :  15:08:32  Show Profile  Visit tkizer's Homepage  Reply with Quote
I don't understand your query. The variable usage makes no sense. Why are you putting created_by into @user_id and also using @user_id in the WHERE clause but haven't set it to anything?

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
37123 Posts

Posted - 07/17/2014 :  15:09:21  Show Profile  Visit tkizer's Homepage  Reply with Quote
If you want to see the result, you would run this:
select @user_id

But it's unlikely to show anything because your code isn't correct. I am not sure what it should be as you haven't provided that detail.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Pasi
Posting Yak Master

152 Posts

Posted - 07/17/2014 :  16:31:20  Show Profile  Reply with Quote
I am trying to get the user_id (from user_mstr table) currently logged in to application and pass it on to my excel sheet as well as first_name,last_name, created_by ( "Created_by" which is the same as user_id) from ngweb_bulk_enrollment table. So I tried to query 2 tables using 2 select statement, and not sure if I am doing it correctly?

The only thing is I don't want store proc, I want a query to run from excel but, not sure what I am asking has to be a store proc only or not?

Hope this helps.
Thanks.

quote:
Originally posted by tkizer

If you want to see the result, you would run this:
select @user_id

But it's unlikely to show anything because your code isn't correct. I am not sure what it should be as you haven't provided that detail.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/

Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 07/17/2014 :  16:38:23  Show Profile  Reply with Quote
I'm completely lost. You are talking about a user using an application and passing information to excel and getting results in SQL management Studio..???

Here are some links that might help organize your thoughts so you can post a better, more organized, question so we can help you better:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000