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.
Author |
Topic |
Pasi
Posting Yak Master
166 Posts |
Posted - 2014-07-17 : 14:38:46
|
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.begindeclare @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
38200 Posts |
Posted - 2014-07-17 : 15:08:32
|
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 KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-07-17 : 15:09:21
|
If you want to see the result, you would run this:select @user_idBut 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 KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
Pasi
Posting Yak Master
166 Posts |
Posted - 2014-07-17 : 16:31:20
|
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_idBut 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 KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/
|
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2014-07-17 : 16:38:23
|
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 |
|
|
|
|
|
|
|