We help IT Professionals succeed at work.

How to enter go in sql output with a new line

deepakontheweb
on
671 Views
Last Modified: 2012-08-13
Hi all,

I have a sql code to return some sql coding in output, but I need to add go with every new line within sql output. my code is like....

SELECT 'sp_addlogin '''+ left(name + ''', ',100), password, + ', ''' + db_name(dbid) + + ''', ''' + + language + ''', ', sid, ', skip_encryption' FROM master.dbo.sysxlogins where srvid is null and xstatus&4 <> 4 order by name

its output seems to be like below: -


sp_addlogin 'a',       0x0100D352F213FFD620719C05094A34E712C708BC0B605DC14C1E9DF97ED44900336D0AD768D3A1005DBF8F3AEF0C      , 'master', 'us_english',       0xD43E490C8AB08340916D7421A932F3FE      , skip_encryption
sp_addlogin 'aa',       0x0100ED52D5630558AEC6EE1FCCBAD68FEF3621597539661E1AA74BCE6B1271FB0361EBEA5DD6C06DAD492C389DC9      , 'master', 'us_english',       0x2E479968DF7E85458385F44D6E182CDF      , skip_encryption
sp_addlogin 'aaa',       0x01000053BF5FB8622A48BDDBEB80F70CC79D47585BB30005AB265C118207CB4BC6816C58EFEA667326707AE80573      , 'master', 'us_english',       0xDAA27D79D380C04EB642F9238C156401      , skip_encryption


is it possible to add go with new line like below.....



sp_addlogin 'a',       0x0100D352F213FFD620719C05094A34E712C708BC0B605DC14C1E9DF97ED44900336D0AD768D3A1005DBF8F3AEF0C      , 'master', 'us_english',       0xD43E490C8AB08340916D7421A932F3FE      , skip_encryption
go
sp_addlogin 'aa',       0x0100ED52D5630558AEC6EE1FCCBAD68FEF3621597539661E1AA74BCE6B1271FB0361EBEA5DD6C06DAD492C389DC9      , 'master', 'us_english',       0x2E479968DF7E85458385F44D6E182CDF      , skip_encryption
go
sp_addlogin 'aaa',       0x01000053BF5FB8622A48BDDBEB80F70CC79D47585BB30005AB265C118207CB4BC6816C58EFEA667326707AE80573      , 'master', 'us_english',       0xDAA27D79D380C04EB642F9238C156401      , skip_encryption


I have used cursor's for it but that do not display password... Hence request you all to help me as soon as possible.

Thanks in advance.

Deepak Kumar.
Comment
Watch Question

Commented:
you could try:

SELECT 'sp_addlogin '''+ left(name + ''', ',100), password, + ', ''' + db_name(dbid) + + ''', ''' + + language + ''', ', sid, ', skip_encryption' + CHAR(10) + 'GO' + CHAR(10) FROM master.dbo.sysxlogins where srvid is null and xstatus&4 <> 4 order by name
CERTIFIED EXPERT

Commented:
Yes. BulZeye's query will work. If you run this sql from query analyzer make sure "Query/Results in Text" option is selected using "Query/Results in Text" menu item.

If "Query/Results in Grid" is selected then you will not see the next line.

best regards-
Dishan FernandoSoftware Engineer / DBA

Commented:
Hi

Your Sql gives wrong output..

try this..

SELECT 'sp_addlogin '''+ left(name + ''' ',100), password, + '''' + db_name(dbid) + '''', ''''+ language + '''', sid, ' skip_encryption'
+CHAR(10)+ 'GO'
FROM master.dbo.sysxlogins
where srvid is null and xstatus&4 <> 4 order by name

hth
dishan
Top Expert 2004

Commented:
Just my .02 here....very bad idea to run queries against the sysxlogins table.....Of all the system tables that are prone to change--this is probably the most likely.....
Senior DBA
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks Scottpletcher... I have done with my coding....(I admit that, was really making this silly mistake.... heheheheheheh)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.