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
 OSQL QUERY TOO LONG ERROR
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kgundava
Yak Posting Veteran

66 Posts

Posted - 07/21/2011 :  19:53:19  Show Profile  Reply with Quote
Hi All,
I have a query which i am trying to run and it has more than 2500 characters in it.When i try to execute this query i am getting the Query too long error.Please let me how to fix this. I have windows 2008 R2 installed
Plz see the sample query below.....

DECLARE @CMD88 varchar(8000)
Select @CMD88 = 'osql -E -S -Q"select "MANDT","BUKRS","KUNNR","UMSKS","UMSKZ","AUGDT","AUGBL","ZUONR","GJAHR","BELNR","BUZEI","BUDAT","BLDAT","CPUDT","WAERS","XBLNR","BLART","MONAT","BSCHL","ZUMSK","SHKZG","GSBER","MWSKZ","DMBTR","WRBTR","MWSTS","WMWST","BDIFF","BDIF2","SGTXT","PROJN","AUFNR","ANLN1","ANLN2","SAKNR","HKONT","FKONT","FILKD","ZFBDT","ZTERM","ZBD1T","ZBD2T","ZBD3T","ZBD1P","ZBD2P","SKFBT","SKNTO","WSKTO","ZLSCH","ZLSPR","ZBFIX","HBKID","BVTYP","REBZG","REBZJ","REBZZ","SAMNR","ANFBN","ANFBJ","ANFBU","ANFAE","MANSP","MSCHL","MADAT","MANST","MABER","XNETB","XANET","XCPDD","XINVE","XZAHL","MWSK1","DMBT1","WRBT1","MWSK2","DMBT2","WRBT2","MWSK3","DMBT3","WRBT3","BSTAT","VBUND","VBELN","REBZT","INFAE","STCEG","EGBLD","EGLLD","RSTGR","XNOZA","VERTT","VERTN","VBEWA","WVERW","PROJK","FIPOS","NPLNR","AUFPL","APLZL","XEGDR","DMBE2","DMBE3","DMB21","DMB22","DMB23","DMB31","DMB32","DMB33","BDIF3","XRAGL","UZAWE","XSTOV","MWST2","MWST3","SKNT2","SKNT3","XREF1","XREF2","XARCH","PSWSL","PSWBT","LZBKZ","LANDL","IMKEY","VBEL2","VPOS2","POSN2","ETEN2","FISTL","GEBER","DABRZ","XNEGP","KOSTL","RFZEI","KKBER","EMPFB","PRCTR","XREF3","QSSKZ","ZINKZ","DTWS1","DTWS2","DTWS3","DTWS4","XPYPR","KIDNO","ABSBT","CCBTC","PYCUR","PYAMT","BUPLA","SECCO","CESSION_KZ","PPDIFF","PPDIF2","PPDIF3","FKBER" from DB..Ganta.[Test] Except select "MANDT","BUKRS","KUNNR","UMSKS","UMSKZ","AUGDT","AUGBL","ZUONR","GJAHR","BELNR","BUZEI","BUDAT","BLDAT","CPUDT","WAERS","XBLNR","BLART","MONAT","BSCHL","ZUMSK","SHKZG","GSBER","MWSKZ","DMBTR","WRBTR","MWSTS","WMWST","BDIFF","BDIF2","SGTXT","PROJN","AUFNR","ANLN1","ANLN2","SAKNR","HKONT","FKONT","FILKD","ZFBDT","ZTERM","ZBD1T","ZBD2T","ZBD3T","ZBD1P","ZBD2P","SKFBT","SKNTO","WSKTO","ZLSCH","ZLSPR","ZBFIX","HBKID","BVTYP","REBZG","REBZJ","REBZZ","SAMNR","ANFBN","ANFBJ","ANFBU","ANFAE","MANSP","MSCHL","MADAT","MANST","MABER","XNETB","XANET","XCPDD","XINVE","XZAHL","MWSK1","DMBT1","WRBT1","MWSK2","DMBT2","WRBT2","MWSK3","DMBT3","WRBT3","BSTAT","VBUND","VBELN","REBZT","INFAE","STCEG","EGBLD","EGLLD","RSTGR","XNOZA","VERTT","VERTN","VBEWA","WVERW","PROJK","FIPOS","NPLNR","AUFPL","APLZL","XEGDR","DMBE2","DMBE3","DMB21","DMB22","DMB23","DMB31","DMB32","DMB33","BDIF3","XRAGL","UZAWE","XSTOV","MWST2","MWST3","SKNT2","SKNT3","XREF1","XREF2","XARCH","PSWSL","PSWBT","LZBKZ","LANDL","IMKEY","VBEL2","VPOS2","POSN2","ETEN2","FISTL","GEBER","DABRZ","XNEGP","KOSTL","RFZEI","KKBER","EMPFB","PRCTR","XREF3","QSSKZ","ZINKZ","DTWS1","DTWS2","DTWS3","DTWS4","XPYPR","KIDNO","ABSBT","CCBTC","PYCUR","PYAMT","BUPLA","SECCO","CESSION_KZ","PPDIFF","PPDIF2","PPDIF3","FKBER" from DB1..Ganta.[Test]"-o"E:\R\1.txt"'
EXEC master..xp_cmdshell @cmd88

tkizer
Almighty SQL Goddess

USA
35934 Posts

Posted - 07/21/2011 :  19:55:12  Show Profile  Visit tkizer's Homepage  Reply with Quote
Put your query into a view, and then query the view from osql. By the way, you should be using sqlcmd if you are on SQL 2005 or greater.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

kgundava
Yak Posting Veteran

66 Posts

Posted - 07/21/2011 :  19:59:43  Show Profile  Reply with Quote
I am really new to SQL server. I did not understand the solution :( can you give me a example( i.e. How can i put the query into a view)
Also is it not possible to make this one work at OSQL level???
Thanks a ton!!!!!
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
35934 Posts

Posted - 07/21/2011 :  20:09:28  Show Profile  Visit tkizer's Homepage  Reply with Quote
create view SomeViewName
as
your query goes here
go

Hit F5 to create the view.

Now use SomeViewName in your osql command: select * from SomeViewName

It should now work.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

Edited by - tkizer on 07/21/2011 20:09:47
Go to Top of Page

kgundava
Yak Posting Veteran

66 Posts

Posted - 07/22/2011 :  15:53:38  Show Profile  Reply with Quote
Thanks for the reply.When i started executing the select * from the view
using osql i got a Oracle oledb connection lost error (Linked server to Oracle from sql server). Please let me know if it is possible to run huge queries which would take 3-4 hours from OSQL?? or does it have any limitations.
Thanks.....

Go to Top of Page

tkizer
Almighty SQL Goddess

USA
35934 Posts

Posted - 07/22/2011 :  16:17:07  Show Profile  Visit tkizer's Homepage  Reply with Quote
Osql doesn't have that limitation as far as I know. You may want to try sqlcmd though as osql has been deprecated and isn't as good.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
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.08 seconds. Powered By: Snitz Forums 2000